interactive · 11 min

Structured Output

Objective: make the policy return a constrained response and parse it into a (kind, argument) action your loop can trust.

The mock returns strings shaped KIND: argument. The agent never acts on raw text — it parses, validates the kind, and only then proceeds.

Model

Mock is the default and free. Switch the Model toggle above to Real (your key) to run this same code on your own OpenAI-compatible model.

This MockLLM is the same seam from Foundations, here named llm for the model’s perspective — decide routes to it in mock mode and to the real model in real mode, so the rest of the loop never changes.

Parsing + validating is the whole lesson: the model is untrusted input; the (kind, argument) tuple is the trusted contract your loop runs on.

Best practice: define the output grammar and a total parser with a safe fallback. An unparseable response must degrade to a defined action, never crash the loop.

Next: Prompting Pitfalls