OpenAI Structured Output icon

OpenAI Structured Output

Consume Open AI

Extract JSON

AI-generated

Overview

The "OpenAI Structured Output" node enables users to send text input to an OpenAI language model and receive a structured JSON response that strictly follows a user-defined JSON Schema. This is particularly useful when you want to extract specific, well-structured data from unstructured text using AI, such as parsing form responses, extracting entities, or converting natural language into a predefined data format.

Common scenarios include:

  • Extracting structured information (e.g., contact details, dates, or product specifications) from freeform text.
  • Validating and formatting AI-generated content to match a strict schema for downstream processing.
  • Automating data extraction workflows where consistent JSON output is required.

Example: Given a block of customer feedback text, the node can extract sentiment scores, key topics, and customer metadata in a JSON object matching your schema.

Properties

Name Meaning
Model The OpenAI model to use for generating the structured output. Options include various GPT-4 and GPT-O models such as "gpt-4.1", "gpt-4o", "gpt-4o-mini", "gpt-o1-model", "gpt-o1-mini", "gpt-o3", and "gpt-o3-mini".
JSON Schema A JSON Schema definition that specifies the exact structure the output JSON must follow. The model will be instructed to return only JSON matching this schema, ensuring strict adherence to the expected format.
Text The input text string to be processed by the model. This is the raw content from which structured data will be extracted according to the JSON Schema.
Temperature Controls the randomness of the model's output. Values range from 0 to 1, where lower values make the output more deterministic and repetitive, and higher values increase creativity and variability in the response.

Output

The node outputs JSON data under the json field of each item. This JSON strictly conforms to the user-provided JSON Schema, containing the extracted or transformed data as defined by the schema.

If the node supports binary data output, it is not indicated in the provided code or properties, so the output is purely JSON structured data.

Dependencies

  • Requires an API key credential for authenticating with the OpenAI API.
  • The node sends requests to the OpenAI API endpoint, defaulting to https://api.openai.com unless overridden by credentials.
  • Proper configuration of the OpenAI API key and endpoint URL in n8n credentials is necessary.

Troubleshooting

  • Invalid JSON Schema: If the JSON Schema provided is malformed or invalid JSON, the node may fail or produce errors. Ensure the schema is valid JSON and correctly formatted.
  • Model Response Not Matching Schema: If the model returns data not conforming to the schema, check the schema's strictness and the temperature setting. Lower temperature values help enforce deterministic outputs.
  • API Authentication Errors: Missing or incorrect API keys will cause authentication failures. Verify that the OpenAI API key credential is correctly set up.
  • Rate Limits or Quotas: Hitting OpenAI API rate limits can cause request failures. Monitor usage and adjust accordingly.
  • Empty or Invalid Input Text: Providing empty or nonsensical input text may result in unexpected outputs or errors.

Links and References

Discussion