Session 3. Structured outputs — Wed 16 Sep

Quick quiz (ungraded)

Q1: The model returns all four required fields plus "source_url". What does parse_research_answer do?

  • A field nobody asked for is a field nobody validates. A contract that accepts anything is not a contract.

  • Silent is the problem. You would never learn the model is drifting away from the shape you asked for.

  • Correct. The gate is set equality, so it reports missing=[] unknown=['source_url'] and nothing half-validated gets through.

Q2: The first reply fails to parse, the retry fails too. What comes back?

  • Retry until it works has no bound on cost or latency. A model that misread the instruction misreads it the fourth time too.

  • That pushes the decision onto code with less context than the agent had, and every caller has to remember to check.

  • Correct. A typed refusal travels the same plumbing as a good answer and arrives where a person can see it.

Q3: A reply parses cleanly and cites internal-wiki, which retrieval never returned. What happens?

  • Schema conformance is necessary, never sufficient. The citation is a doc id the retriever never produced.

  • Correct. The application verifies citations against what retrieval actually returned; the trace records the strip.

  • The parser only knows the shape. It has never seen the retrieval result, so it cannot know that doc id is fabricated.

Q4: Your unsupported golden question is correct. What does its trace look like?

  • Correct. The refusal happens before the model is asked, so it costs nothing and cannot hallucinate.

  • That works too, and it spends a call to learn what retrieval already knew. Refuse before you spend.

  • Two calls means the repair budget fired on a parse failure. That is a different failure from an unsupported question.

Q5: Why does the schema carry a needs_human_review field at all?

  • It is the one signal that a flagged refusal produces. Ignoring it is how a refusal gets read as an answer.

  • Correct. A schema that cannot say I don't know pushes the model into inventing, because every accepted shape claims to know.

  • The schema is yours. The provider returns text; every field in it is a choice you made and can test.