Principle:Openai Openai node Parsed Output Consumption
| Knowledge Sources | |
|---|---|
| Domains | Schema_Validation, NLP |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
A principle for consuming typed, schema-validated output from language model responses where raw JSON content has been automatically parsed into application-level objects.
Description
Parsed Output Consumption is the final step in the structured output pipeline. After the API response is received and parsed, the consumer accesses the typed result via the message.parsed property (Chat Completions) or output_parsed property (Responses API). The parsed value is null when the model issues a refusal or when content is empty.
This principle addresses the common pattern of: (1) checking for refusals, (2) accessing the parsed content, and (3) using it with full TypeScript type safety.
Usage
Use this pattern after calling completions.parse() or responses.parse(). Always check for null (refusal or empty content) before using the parsed value.
Theoretical Basis
Parsed output consumption follows a Nullable Result Pattern:
// Chat Completions pattern:
completion = await parse(params)
message = completion.choices[0].message
if message.refusal:
handle_refusal(message.refusal)
else if message.parsed:
use_typed_data(message.parsed) // TypeScript type: ParsedT
// Responses API pattern:
response = await responses.parse(params)
if response.output_parsed:
use_typed_data(response.output_parsed) // TypeScript type: ParsedT
The parsed property is typed as ParsedT | null, enforcing null-checking at the type level.