How to Stream a Structured Model Response and Parse Its JSON Fields as They Arrive
Open a streaming structured response, parse each JSON field as it arrives, and handle an incomplete stream.
THE FIELD GUIDE
Understand model formats, context windows, quantization, embeddings, and sampling before choosing settings for a real task.
Open a streaming structured response, parse each JSON field as it arrives, and handle an incomplete stream.
Use a nested schema with a steps list and a final answer field so reasoning and result stay separate.
Check the response for a refusal field, present it cleanly, and never treat it as parsed data.
Define an entity schema, send unstructured text, and check every extracted entity really appears in the source.
Put an enum in the schema for a field your code branches on, then check no other value ever comes back.
Parse the model reply, validate it field by field against the schema, and retry with the error when it fails.
Define the schema in code with a Pydantic BaseModel, parse the structured reply, and read the typed result.
Define a weather function with a schema, read the model tool call, run the function, and send the result back.
Compare what each mode guarantees, then pick Structured Outputs when the shape matters and JSON mode when it does not.
Define a JSON Schema response format with strict mode so model output matches the shape your code expects.