Back to Autogpt

Text

docs/integrations/block-integrations/text.md

0.6.4421.5 KB
Original Source

Text

<!-- MANUAL: file_description -->

Blocks for text processing including formatting, extraction, transformation, splitting, combining, and template rendering.

<!-- END MANUAL -->

Code Extraction

What it is

Extracts code blocks from text and identifies their programming languages

How it works

<!-- MANUAL: how_it_works -->

This block parses text content (typically from AI responses) and extracts code blocks enclosed in markdown-style triple backticks. It identifies the programming language from the code fence annotation (e.g., ```python) and routes each extracted code block to the appropriate language-specific output.

The block supports 16 programming languages including Python, JavaScript, HTML, CSS, SQL, and more. Any text that remains after extracting all code blocks is output as "remaining_text", allowing you to process both the code and surrounding context separately.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
textText containing code blocks to extract (e.g., AI response)strYes

Outputs

OutputDescriptionType
errorError message if the operation failedstr
htmlExtracted HTML codestr
cssExtracted CSS codestr
javascriptExtracted JavaScript codestr
pythonExtracted Python codestr
sqlExtracted SQL codestr
javaExtracted Java codestr
cppExtracted C++ codestr
csharpExtracted C# codestr
json_codeExtracted JSON codestr
bashExtracted Bash codestr
phpExtracted PHP codestr
rubyExtracted Ruby codestr
yamlExtracted YAML codestr
markdownExtracted Markdown codestr
typescriptExtracted TypeScript codestr
xmlExtracted XML codestr
remaining_textRemaining text after code extractionstr

Possible use case

<!-- MANUAL: use_case -->

AI Code Generation Pipeline: When an AI model generates a response containing multiple code blocks (HTML, CSS, JavaScript), use this block to separate each language into individual files for a complete web component.

Code Review Automation: Extract Python code from documentation or chat logs to run automated linting, testing, or security scanning on the code portions only.

Technical Documentation Processing: Parse developer tutorials or README files to extract executable code samples while preserving the explanatory text for different processing paths.

<!-- END MANUAL -->

Combine Texts

What it is

This block combines multiple input texts into a single output text.

How it works

<!-- MANUAL: how_it_works -->

The block concatenates all the input texts in the order they are provided, inserting the specified delimiter (if any) between each text.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
inputtext input to combineList[str]Yes
delimiterDelimiter to combine textsstrNo

Outputs

OutputDescriptionType
errorError message if the operation failedstr
outputCombined textstr

Possible use case

<!-- MANUAL: use_case -->

Merging multiple parts of an address (street, city, state, zip code) into a single, formatted address string.

<!-- END MANUAL -->

Countdown Timer

What it is

This block triggers after a specified duration.

How it works

<!-- MANUAL: how_it_works -->

The Countdown Timer block pauses workflow execution for a specified duration before continuing. You can set the delay using any combination of seconds, minutes, hours, and days. When the timer completes, it outputs your specified message (or "timer finished" by default).

The block supports a repeat parameter, allowing the timer to fire multiple times in sequence—useful for creating periodic triggers within your workflow. The timer uses async sleep, so it doesn't block other concurrent operations in the system.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
input_messageMessage to output after the timer finishesInput MessageNo
secondsDuration in secondsint | strNo
minutesDuration in minutesint | strNo
hoursDuration in hoursint | strNo
daysDuration in daysint | strNo
repeatNumber of times to repeat the timerintNo

Outputs

OutputDescriptionType
errorError message if the operation failedstr
output_messageMessage after the timer finishesOutput Message

Possible use case

<!-- MANUAL: use_case -->

Rate Limiting: Add a delay between API calls to respect rate limits when processing large batches of data through external services.

Scheduled Notifications: Create a workflow that waits a specific time after an event (like a form submission) before sending a follow-up email or notification.

Polling Workflows: Use the repeat feature to periodically check for updates, such as monitoring a file location or checking an API endpoint every few minutes.

<!-- END MANUAL -->

Extract Text Information

What it is

This block extracts the text from the given text using the pattern (regex).

How it works

<!-- MANUAL: how_it_works -->

The block uses regular expressions to find the specified pattern in the text. It then extracts a particular group from the match, which can be the entire match or a specific captured group.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
textText to parseTextYes
patternPattern (Regex) to parsestrYes
groupGroup number to extractintNo
case_sensitiveCase sensitive matchboolNo
dot_allDot matches allboolNo
find_allFind all matchesboolNo

Outputs

OutputDescriptionType
errorError message if the operation failedstr
positiveExtracted textstr
negativeOriginal textstr
matched_resultsList of matched resultsList[str]
matched_countNumber of matched resultsint

Possible use case

<!-- MANUAL: use_case -->

Extracting phone numbers or email addresses from a large body of text, such as a customer database.

<!-- END MANUAL -->

Fill Text Template

What it is

This block formats the given texts using the format template.

How it works

<!-- MANUAL: how_it_works -->

The block uses a template engine to replace placeholders in the format string with the provided values. It supports both simple placeholder replacement and more complex operations like loops.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
valuesValues (dict) to be used in format. These values can be used by putting them in double curly braces in the format template. e.g. {{value_name}}.Dict[str, Any]Yes
formatTemplate to format the text using values. Use Jinja2 syntax.strYes
escape_htmlWhether to escape special characters in the inserted values to be HTML-safe. Enable for HTML output, disable for plain text.boolNo

Outputs

OutputDescriptionType
errorError message if the operation failedstr
outputFormatted textstr

Possible use case

<!-- MANUAL: use_case -->

Generating personalized email messages by filling a template with customer-specific information like name, order details, or account status.

<!-- END MANUAL -->

Get Current Date

What it is

This block outputs the current date with an optional offset.

How it works

<!-- MANUAL: how_it_works -->

This block retrieves the current date from the system clock and formats it according to your preferences. You can specify an offset in days to get past or future dates (negative values for past dates, positive for future).

The block supports two format types: strftime (customizable format strings like "%Y-%m-%d" or "%B %d, %Y") and ISO 8601 (standard format YYYY-MM-DD). You can also configure the timezone—either specify a specific timezone or use the user's profile timezone setting.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
triggerTrigger any data to output the current datestrYes
offsetOffset in days from the current dateint | strNo
format_typeFormat type for date output (strftime with custom format or ISO 8601)Format TypeNo

Outputs

OutputDescriptionType
errorError message if the operation failedstr
dateCurrent date in the specified format (default: YYYY-MM-DD)str

Possible use case

<!-- MANUAL: use_case -->

Daily Report Generation: Use the current date as a filename suffix or report header when generating automated daily summaries or exports.

Deadline Tracking: Calculate dates relative to today using the offset feature—for example, find the date 30 days from now for payment due dates or project milestones.

Date-Based Filtering: Get today's date to filter records, events, or tasks that are relevant to the current day in your workflow.

<!-- END MANUAL -->

Get Current Date And Time

What it is

This block outputs the current date and time.

How it works

<!-- MANUAL: how_it_works -->

This block outputs the current date and time from the system clock, formatted according to your specifications. It supports both strftime custom formats (like "%Y-%m-%d %H:%M:%S") and ISO 8601/RFC 3339 format for maximum compatibility with APIs and databases.

You can configure the timezone to use either a specific timezone (e.g., "America/New_York") or the user's profile timezone. The ISO 8601 format option includes an optional microseconds precision setting for applications requiring high-resolution timestamps.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
triggerTrigger any data to output the current date and timestrYes
format_typeFormat type for date and time output (strftime with custom format or ISO 8601/RFC 3339)Format TypeNo

Outputs

OutputDescriptionType
errorError message if the operation failedstr
date_timeCurrent date and time in the specified format (default: YYYY-MM-DD HH:MM:SS)str

Possible use case

<!-- MANUAL: use_case -->

Audit Logging: Add precise timestamps to records when logging user actions, system events, or data changes in your workflow.

API Requests: Generate ISO 8601 formatted timestamps required by many REST APIs for request authentication or data submission.

Scheduling Logic: Compare the current date/time against scheduled events to trigger time-sensitive automations like sending reminders or processing batch jobs.

<!-- END MANUAL -->

Get Current Time

What it is

This block outputs the current time.

How it works

<!-- MANUAL: how_it_works -->

This block outputs just the current time (without date) from the system clock. It supports strftime custom formats (like "%H:%M:%S" for 24-hour time or "%I:%M %p" for 12-hour time with AM/PM) and ISO 8601 time format.

The timezone can be configured to a specific timezone or to use the user's profile timezone setting. When using ISO 8601 format, the output includes the timezone offset and an optional microseconds component for precision timing needs.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
triggerTrigger any data to output the current timestrYes
format_typeFormat type for time output (strftime with custom format or ISO 8601)Format TypeNo

Outputs

OutputDescriptionType
errorError message if the operation failedstr
timeCurrent time in the specified format (default: %H:%M:%S)str

Possible use case

<!-- MANUAL: use_case -->

Business Hours Check: Get the current time to determine if a request falls within business hours and route it accordingly (live support vs. after-hours message).

Time-Based Greetings: Generate personalized greetings ("Good morning", "Good afternoon") based on the current time of day.

Shift Scheduling: Determine which team or process should handle a task based on the current time and configured shift schedules.

<!-- END MANUAL -->

Match Text Pattern

What it is

Matches text against a regex pattern and forwards data to positive or negative output based on the match.

How it works

<!-- MANUAL: how_it_works -->

The block uses regular expressions to search for the specified pattern within the input text. It considers options like case sensitivity and whether the dot should match all characters.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
textText to matchTextYes
matchPattern (Regex) to matchstrYes
dataData to be forwarded to outputDataYes
case_sensitiveCase sensitive matchboolNo
dot_allDot matches allboolNo

Outputs

OutputDescriptionType
errorError message if the operation failedstr
positiveOutput data if match is foundPositive
negativeOutput data if match is not foundNegative

Possible use case

<!-- MANUAL: use_case -->

Filtering customer feedback messages based on specific keywords or phrases to categorize them as positive or negative reviews.

<!-- END MANUAL -->

Text Decoder

What it is

Decodes a string containing escape sequences into actual text

How it works

<!-- MANUAL: how_it_works -->

This block processes a text string and converts escape sequences (like \n, \t, \, \uXXXX) into their actual character representations. For example, the literal text "Hello\nWorld" becomes "Hello" followed by an actual newline, then "World".

This is useful when working with data from APIs or files where escape sequences are stored as literal text rather than being interpreted as special characters. The block handles standard escape sequences including newlines, tabs, Unicode characters, and more.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
textA string containing escaped characters to be decodedstrYes

Outputs

OutputDescriptionType
errorError message if the operation failedstr
decoded_textThe decoded text with escape sequences processedstr

Possible use case

<!-- MANUAL: use_case -->

JSON Data Processing: When parsing JSON strings that contain escaped characters (like "\n" for newlines in a message field), decode them to display properly formatted text to users.

Log File Processing: Process log entries where special characters are escaped, converting them to their actual representations for proper parsing or display.

API Response Handling: Decode text from APIs that return escaped content, ensuring special characters like tabs and newlines render correctly in your output.

<!-- END MANUAL -->

Text Encoder

What it is

Encodes a string by converting special characters into escape sequences

How it works

<!-- MANUAL: how_it_works -->

The Text Encoder takes the input string and applies Python's unicode_escape encoding (equivalent to codecs.encode(text, "unicode_escape").decode("utf-8")) to transform special characters like newlines, tabs, and backslashes into their escaped forms.

The block relies on the input schema to ensure the value is a string; non-string inputs are rejected by validation, and any encoding failures surface as block errors. Non-ASCII characters are emitted as \uXXXX sequences, which is useful for ASCII-only payloads.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
textA string containing special characters to be encodedstrYes

Outputs

OutputDescriptionType
errorError message if encoding failsstr
encoded_textThe encoded text with special characters converted to escape sequencesstr

Possible use case

<!-- MANUAL: use_case -->

JSON Payload Preparation: Encode multiline or quoted text before embedding it in JSON string fields to ensure proper escaping.

Config/ENV Generation: Convert template text into escaped strings for .env or YAML values that require special character handling.

Snapshot Fixtures: Produce stable escaped strings for golden files or API tests where consistent text representation is needed.

<!-- END MANUAL -->

Text Replace

What it is

This block is used to replace a text with a new text.

How it works

<!-- MANUAL: how_it_works -->

This block performs a simple find-and-replace operation on text. It searches for all occurrences of the "old" string within your input text and replaces each one with the "new" string. The replacement is case-sensitive and matches exact strings.

Unlike regex-based replacements, this block performs literal string matching, making it straightforward and predictable for common text substitution tasks. All instances of the target string are replaced in a single operation.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
textThe text to replace.strYes
oldThe old text to replace.strYes
newThe new text to replace with.strYes

Outputs

OutputDescriptionType
errorError message if the operation failedstr
outputThe text with the replaced text.str

Possible use case

<!-- MANUAL: use_case -->

Data Sanitization: Replace sensitive information like placeholder tokens with actual values, or redact personal information before displaying or storing text.

Template Customization: Swap out placeholder text in templates (like "[COMPANY_NAME]" or "{{user}}") with actual values before sending emails or generating documents.

URL Manipulation: Modify URLs by replacing domain names, query parameters, or path segments to redirect requests or update links dynamically.

<!-- END MANUAL -->

Text Split

What it is

This block is used to split a text into a list of strings.

How it works

<!-- MANUAL: how_it_works -->

This block takes a text string and divides it into a list of substrings based on a specified delimiter. For example, splitting "apple,banana,cherry" by comma results in ["apple", "banana", "cherry"].

By default, the block also strips whitespace from each resulting substring (controlled by the "strip" option). If your input text is empty, the block returns an empty list. This is useful for parsing structured text data like CSV values, tags, or any delimited content.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
textThe text to split.strYes
delimiterThe delimiter to split the text by.strYes
stripWhether to strip the text.boolNo

Outputs

OutputDescriptionType
errorError message if the operation failedstr
textsThe text split into a list of strings.List[str]

Possible use case

<!-- MANUAL: use_case -->

Tag Processing: Split a comma-separated list of tags or keywords into individual items for processing, filtering, or database storage.

Line-by-Line Processing: Split a multi-line text file by newline characters to process each line independently in your workflow.

Parsing User Input: Break apart user-submitted lists (like email addresses separated by semicolons) into individual items for validation and processing.

<!-- END MANUAL -->

Word Character Count

What it is

Counts the number of words and characters in a given text.

How it works

<!-- MANUAL: how_it_works -->

This block analyzes input text and returns two metrics: the total number of words and the total number of characters. Words are counted by splitting the text on whitespace, so "Hello World" counts as 2 words. Characters include all characters in the text, including spaces and punctuation.

This provides a quick way to measure text length for validation, summarization checks, or content analysis without needing custom logic.

<!-- END MANUAL -->

Inputs

InputDescriptionTypeRequired
textInput text to count words and charactersstrYes

Outputs

OutputDescriptionType
errorError message if the counting operation failedstr
word_countNumber of words in the input textint
character_countNumber of characters in the input textint

Possible use case

<!-- MANUAL: use_case -->

Content Validation: Check if user-submitted text (like reviews or comments) meets minimum or maximum length requirements before accepting it.

AI Prompt Optimization: Measure prompt length to ensure it fits within token limits before sending to language models, potentially triggering summarization if too long.

Social Media Preparation: Verify that text content fits within platform character limits (like Twitter's 280 characters) before attempting to post.

<!-- END MANUAL -->