Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

Agent Foundations

Free · sign in to start and track progress

1 · What agents are

  • 1What is an agent?
  • 2Tools and the agent-computer interface
  • 3Context engineering

2 · Making agents dependable

  • 4Structured outputs and grounding

    Exercise answers

    • Answer: Produce and verify grounded title reports
    • Answer: Same report through the Agent SDK
  • 5Workflow patterns
  • 6Risk and first evals
CapstoneA document review agent in Claude CodeReference implementation

Module 2 · Making agents dependable · Lesson 4

Structured outputs and grounding

Make an agent return typed, schema-validated JSON in which every finding carries an exact quote that your code can check against the source document.

75 min 1 video 3 exercises 7-question quiz Answers
Setup for the exercises:Install Claude CodeNode.js, pnpm and TypeScriptGet an OpenRouter keyOpenRouter or a local model?Local models with Ollama

By the end of this lesson you can

  • Design a Zod schema for a title-review report that uses enums, required evidence and explicit 'not found' values
  • Get schema-validated JSON from Claude Code headless mode, and explain how the Agent SDK's outputFormat does the same
  • Implement a validate-and-retry loop and explain why schema validity does not imply correctness
  • Ground findings in evidence quotes and verify each quote against the source in code

On this page

  • Why free text isn't enough
  • Designing the schema
  • Getting structured output from the harness
  • Validate, then retry with the errors
  • Schema-valid is not the same as correct
  • Grounding: quotes you can check
  • Extraction from messy documents
  • Misconceptions and limits
  • Where this goes next
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01Why free text isn't enough
  2. 02Designing the schema
  3. 03Getting structured output from the harness
  4. 04Validate, then retry with the errors
  5. 05Schema-valid is not the same as correct
  6. 06Grounding: quotes you can check
  7. 07Extraction from messy documents
  8. 08Misconceptions and limits
  9. 09Where this goes next
  10. 10Summary

Sources & further reading

  • LegalBench: A Collaboratively Built Benchmark for Measuring Legal Reasoning in Large Language ModelsPaper · Guha et al. · Stanford · 2023A benchmark of 162 legal reasoning tasks built with legal professionals. Skim the task typology (issue-spotting, rule-recall, interpretation and more) to see which legal tasks models find hard.
  • Get structured output from agentsDocs · AnthropicHow the Agent SDK validates output against a JSON Schema (including Zod via z.toJSONSchema with the draft-7 target) and re-prompts on mismatch. Read the quick start, the Zod section and error handling.
  • Run Claude Code programmatically (headless mode)Docs · AnthropicThe --output-format json and --json-schema flags used in this lesson's exercises, and the structured_output field in the response.
  • Reduce hallucinationsDocs · AnthropicShort and practical. The techniques used here come from it - allow the model to say it doesn't know, extract word-for-word quotes first, and retract claims without a supporting quote.
  • CitationsDocs · AnthropicThe Claude API's built-in citations feature, which returns the exact passages supporting each claim. Useful context for when you build on the API rather than in Claude Code.
  • How to read a title registerDocs · HM Land RegistryWhat each part of the register contains, which is the domain model behind the schema in this lesson.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 10 more sections
  • 3 hands-on exercises
  • A 7-question quiz
  • Progress, quiz scores and bookmarks