Documentation / guides
Overview
Request, validate, extract, and strictly decode one JSON object from model output.
Looprig structured output has three separate boundaries: request admission, response representation, and typed decoding. OutputSchema describes the request; ValidateOutputSchema checks the portable subset; StructuredResult extracts one JSON object; DecodeOutput strictly decodes it into a caller-owned struct.
End-to-end path
%%{init: {"theme":"base","themeVariables":{"background":"#111827","primaryColor":"#1f2937","primaryTextColor":"#f8fafc","primaryBorderColor":"#64748b","lineColor":"#94a3b8","secondaryColor":"#0f172a","tertiaryColor":"#172033","fontFamily":"Inter, ui-sans-serif, system-ui, sans-serif"}}}%%
flowchart LR
schema[OutputSchema] --> validate[ValidateOutputSchema]
validate --> request[Request.Output]
request --> response[Response + AIMessage]
response --> extract[StructuredResult]
extract --> decode[DecodeOutput into struct]
classDef dark fill:#1f2937,stroke:#94a3b8,color:#f8fafc
class schema,validate,request,response,extract,decode dark
No stage trusts provider JSON blindly. Request validation rejects unsupported schema features before encoding. Response extraction ignores thinking blocks but rejects ambiguous block representations and unsafe finish reasons. Decoding uses DisallowUnknownFields, rejects trailing JSON, and commits to the caller’s target only after a complete successful decode.
type Result struct {
Answer string `json:"answer"`
}
var result Result
if err := inference.DecodeOutput(response, &result); err != nil {
return err
}
fmt.Println(result.Answer)
Proof
- Source:
inference/output.go,inference/structured_result.go,inference/structured_errors.go - Tests:
inference/output_test.go,inference/structured_result_test.go
Related: OutputSchema, Schema validation, Typed decoding.