Langflow Micro Tutorials — Document Truncator

Rodrigo Nader
Langflow
Published in
2 min readSep 12, 2023

--

Welcome back to our Langflow micro tutorials series! We’ll continue our journey into very simple Langflow examples, highlighting ideas and the design of custom components.

This article provides a link to download the described flow. Use it to modify and understand the components in use.

Today, we focus on a basic website reading flow that uses a custom component to help truncate documents. Have fun!

Main Features

  • Document Truncator: This is a custom component designed and built from scratch. The primary function of this component is to reduce the text content of a webpage. It does so by retaining only the initial set of characters specified by the truncate_size parameter.

Objective

To help reduce the length of a webpage’s text content to a manageable size before it’s fed into a prompt. Only the beginning portion of the text, up to a specific number of characters, is retained.

For instance, if a webpage has 5,000 characters and the truncate_size is set to 1,000, the Document Truncator will output only the first 1,000 characters from the webpage, discarding the rest.

Notice that this component takes a Langchain Document as input, processes the text inside of it, and outputs a Document again, which is then sent to the Prompt Template.

Download Flow (gist)

--

--