Interview OS
Back to Context Engineering

Library

Structured output

JSON, schemas, function calling.

Prompting

Overview

Structured output forces an LLM to return machine-parseable data (JSON, schema-constrained) instead of prose. It's what makes model responses safe to feed into downstream code without brittle parsing.

How it works

Prompting
SchemaPromptValidateOutputDefinezod/jsonInstructformatParse+retryvalidatorTyped data
ClientServiceEdgeData

Step by step, with examples

  1. 1

    Define

    • Declare a JSON/enum schema.
  2. 2

    Instruct

    • Ask for schema-valid output.
  3. 3

    Parse+retry

    • Reject and repair invalid output.
  4. 4

    Typed data

    • Use it safely downstream.
    • Example: function calling

Overview

Constrain outputs to a schema (JSON mode / function calling) so downstream code can parse reliably.

Common pitfalls

  • No validation/retry on malformed output
  • Over-nesting schemas
  • Free text mixed with JSON

Where this content comes from

For full transparency, this content is curated and verified from these sources:

Frontier-lab prompting & agent guidesRetrieval-augmented generation literatureOppZen-authored context-engineering playbooks