Files
AutoGPT/docs/integrations/block-integrations/encoder_block.md
root 21a1d993b8 docs: address CodeRabbit review feedback for encoder_block.md
- Expand 'How it works' with technical details (unicode_escape encoding, validation, edge cases)
- Add blank lines around tables (MD058)
- Add language tags to fenced code blocks (MD040)
- Replace 'Possible use case' with 3 structured use cases per docs guidelines
- Separate example into its own section
2026-01-29 12:43:45 +00:00

1.9 KiB

Text Encoder

What it is

A tool that converts text containing special characters into escaped text sequences.

What it does

It takes a string of text that contains special characters (like new lines or quotation marks) and converts them into their escape sequence representations (like '\n' for new lines).

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.

Inputs

Input Description
Text The text you want to encode, which may contain special characters like new lines or quotation marks

Outputs

Output Description
Encoded Text The text after processing, with all special characters converted to their escape sequences

Use Case

  • JSON payload preparation: Encode multiline or quoted text before embedding it in JSON string fields.
  • Config/ENV generation: Convert template text into escaped strings for .env or YAML values.
  • Snapshot fixtures: Produce stable escaped strings for golden files or API tests.

Example

Imagine you have a piece of text with line breaks that you need to store in a JSON file or send through an API:

Hello
World!
This is a "quoted" string.

The Text Encoder can convert it into:

Hello\nWorld!\nThis is a "quoted" string.

This is useful when you need to prepare text for storage in formats that require escape sequences, or when sending data to systems that expect encoded text. It's the inverse operation of the Text Decoder block.