Principle:Openai Openai node Response Format Configuration
| Knowledge Sources | |
|---|---|
| Domains | Schema_Validation, NLP |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
A principle for configuring language model response formats with schema-backed auto-parsing so that API responses are automatically validated and typed.
Description
Response Format Configuration wraps a JSON Schema in an AutoParseable format object that the SDK can use both to constrain the model's output and to automatically parse and validate the response. The format object carries both the schema (for the API) and a $parseRaw function (for the SDK) that converts raw JSON string content into a typed, validated object.
This creates a two-way contract: the API ensures the model output conforms to the schema, and the SDK ensures the response is parsed into the correct TypeScript type.
Usage
Use this principle when you need structured, typed output from a language model. This is the second step in the structured output pipeline (after schema definition, before the API call).
Theoretical Basis
Response format configuration implements a Self-Describing Type pattern:
function createParseableFormat(zodSchema, name):
jsonSchema = zodToJsonSchema(zodSchema)
return {
type: 'json_schema',
json_schema: {
name: name,
strict: true,
schema: jsonSchema,
},
// Attached parser for auto-parsing:
$parseRaw: (rawContent) => zodSchema.parse(JSON.parse(rawContent)),
}
The $parseRaw method is a sentinel — the SDK detects its presence and uses it to automatically parse API responses. Without it, the caller must manually parse JSON and validate.