YAML Message Builder icon

YAML Message Builder

Build perfectly formatted YAML message arrays for Dynamic AI Agent. No more indentation or special character issues!

Overview

This node, named "YAML Message Builder," is designed to create perfectly formatted YAML arrays representing chat messages for use with Dynamic AI Agents. It simplifies the process of generating YAML message arrays by handling indentation and special character formatting automatically, eliminating common issues such as incorrect indentation or escaping problems.

Typical use cases include preparing structured chat input for AI agents that require YAML-formatted messages, especially when messages contain multiline text, quotes, backticks, or other special characters. For example, it can be used to format system instructions, user inputs, or assistant responses into a clean YAML array that downstream nodes or services can consume directly.

Properties

Name Meaning
📝 YAML Message Builder generates perfect YAML arrays ready for Dynamic AI Agent. No more indentation headaches! Informational notice describing the node's purpose; no input required.
Message Role The role of the message in the conversation. Options:
- 🤖 System: Defines AI behavior and context
- 👤 User: Represents human input
- 🎯 Assistant: AI responses (examples)
Message Content The actual content of the message. Supports multiline text, quotes, apostrophes, backticks, code blocks, and special characters without needing escaping. This field is required.

Output

The node outputs an array where each item contains a JSON object with the following structure:

  • output: A string containing the YAML representation of an array with one message object. The message object has two fields:

    • role: The selected message role (system, user, or assistant).
    • content: The trimmed message content.

    The YAML output uses 2-space indentation, disables line wrapping, and uses literal block style if the content includes newlines.

  • meta: An object providing metadata about the generated message:

    • role: The message role.
    • contentLength: Length of the original message content.
    • format: Always "array".
    • hasMultiline: Boolean indicating if the content contains multiline text.
    • generatedAt: ISO timestamp of when the YAML was generated.

If an error occurs during processing (e.g., empty content or invalid role), and the node is configured to continue on failure, the output will contain an error message and timestamp instead.

Dependencies

  • Uses the yaml library to convert JavaScript objects into YAML strings.
  • Requires n8n workflow environment for node parameter retrieval and error handling.
  • No external API keys or services are needed.

Troubleshooting

  • Empty Message Content: If the "Message Content" property is empty or only whitespace, the node throws an error stating that message content is required. Ensure this field is filled.
  • Invalid Message Role: If the "Message Role" is not one of system, user, or assistant, an error is thrown. Select a valid role from the provided options.
  • Multiline Content Handling: The node automatically detects multiline content and formats it using YAML's literal block style to preserve line breaks. If you see unexpected formatting, verify your input text.
  • Continue On Fail Behavior: If enabled, errors do not stop execution but are returned as error objects in the output. Otherwise, the node stops on the first error.

Links and References

Discussion