Advanced Output Parser

Output parser with dynamic/expression-based JSON schema support for LangChain/ChatModel nodes.

Overview

The Advanced Output Parser node provides a flexible way to define and validate the output structure of AI or LangChain/ChatModel nodes using JSON schemas. It supports static schemas, dynamic expressions, and schema generation from example JSON data with expression support. This node is particularly useful when you want to enforce a specific output format or parse complex AI-generated responses into structured data.

Common scenarios include:

  • Validating AI model outputs against a predefined JSON schema.
  • Dynamically generating output schemas based on workflow data or examples.
  • Integrating with Chain or Agent nodes as an output parser to ensure consistent data formats.

Practical example:

  • You have an AI model that returns information about US states and their cities. Using this node, you can define a JSON schema that expects a "state" string and a "cities" array of strings, ensuring the AI output matches this structure before further processing.

Properties

Name Meaning
Notice Informational message explaining the node's purpose and usage.
Schema Mode How to define the output schema:
- Static JSON Schema: Use a fixed JSON schema.
- From Example with Expressions: Generate schema from a JSON example supporting expressions.
- Dynamic Expression: Build schema dynamically from workflow data using expressions.
JSON Schema The JSON schema used to structure and validate the output (supports expressions). Visible when Schema Mode is "Static JSON Schema" or "Dynamic Expression".
JSON Example A JSON example used to generate the schema (supports expressions). Visible when Schema Mode is "From Example with Expressions".
Make All Fields Required Whether all fields in the generated schema should be marked as required. Visible only when Schema Mode is "From Example with Expressions".

Output

The node outputs a structured output parser object compatible with LangChain/ChatModel nodes. This parser enforces the defined JSON schema on the AI output, ensuring the data conforms to the expected structure.

  • The json output field represents the parsed and validated data according to the schema.
  • No binary data output is produced by this node.

Dependencies

  • Requires integration with LangChain or ChatModel nodes to use the output parser.
  • Uses JSON schema validation and conversion utilities internally.
  • No external API keys or services are required.
  • Supports n8n expressions for dynamic schema definitions.

Troubleshooting

  • Error creating advanced output parser: This error indicates issues in parsing or validating the provided JSON schema or example. Common causes:

    • Invalid JSON syntax in the schema or example.
    • Expressions within the JSON that fail to evaluate correctly.
    • Incompatible schema structures that cannot be converted to the internal parser format.

    Resolution:

    • Validate JSON syntax carefully.
    • Test expressions separately to ensure they return valid JSON.
    • Simplify schema or example to isolate problematic parts.
  • If the output does not conform to expectations, verify that the schema accurately reflects the desired output structure and that any dynamic expressions resolve correctly at runtime.

Links and References

Discussion