Skip to content

Add structured output tutorial (22-structured-output)#272

Open
builder-ujaladi wants to merge 1 commit into
strands-agents:mainfrom
builder-ujaladi:feat/22-structured-output
Open

Add structured output tutorial (22-structured-output)#272
builder-ujaladi wants to merge 1 commit into
strands-agents:mainfrom
builder-ujaladi:feat/22-structured-output

Conversation

@builder-ujaladi

Copy link
Copy Markdown

Summary

Adds a new 01-learn tutorial covering Strands structured output — returning validated, typed Pydantic objects from agents instead of free-form text. Also registers it in the 01-learn index.

What's included

  • Basic structured output (sync + async) with a flat Pydantic model
  • Complex schemas: nested models, lists, Optional, field constraints, Literal, and Enum
  • Validation & self-correction: an exact-length field_validator the LLM reliably fails on first attempt, plus a cell that prints the agent.messages retry trail so the fail-then-correct loop is visible
  • Tools + structured output: calculator tool feeding a typed result
  • A note on streaming: structured output arrives only in the final event

Peer-review feedback addressed

  • Simplified the architecture diagram to the core concept (prompt + model -> agent -> typed object)
  • Demoted streaming from a standalone section to a note
  • Added interpretation callouts after each output cell, connecting the result back to the Pydantic feature shown
  • Reworked self-correction so the validator genuinely fires, with the retry trail shown via agent.messages

Testing

  • Notebook executed end-to-end against Amazon Bedrock (Claude Sonnet 4.5) — all code cells run with no errors
  • Self-correction verified to fail-then-correct; streaming example produces its final structured object
  • Notebook committed with cleared outputs; follows the use-case structure/README templates

Adds a new 01-learn tutorial covering Strands structured output:
returning validated, typed Pydantic objects from agents instead of
free-form text. Registered in the 01-learn index.

The tutorial covers:
- Basic structured output (sync + async) with a flat Pydantic model
- Complex schemas: nested models, lists, Optional, field constraints,
  Literal, and Enum
- Validation & self-correction: an exact-length field_validator that the
  LLM reliably fails on first attempt, plus a cell that prints the
  agent.messages retry trail so the fail-then-correct loop is visible
- Tools + structured output: calculator tool feeding a typed result
- A note on streaming (structured output arrives only in the final event)

Incorporates peer-review feedback:
- Simplified the architecture diagram to the core concept
  (prompt + model -> agent -> typed object)
- Demoted streaming from a standalone section to a note
- Added interpretation callouts after each output cell connecting the
  result back to the Pydantic feature being shown
- Reworked self-correction so the validator genuinely fires and the
  retry trail is shown via agent.messages

Verified end-to-end against Amazon Bedrock (Claude Sonnet 4.5).
@github-actions

Copy link
Copy Markdown

Latest scan for commit: 19cf311 | Updated: 2026-06-10 04:25:04 UTC

✅ Security Scan Report (PR Files Only)

Scanned Files

  • python/01-learn/22-structured-output/README.md
  • python/01-learn/22-structured-output/images/architecture.png
  • python/01-learn/22-structured-output/requirements.txt
  • python/01-learn/22-structured-output/structured-output.ipynb
  • python/01-learn/README.md

Security Scan Results

Critical High Medium Low Info
0 0 0 0 0

Threshold: High

No security issues detected in your changes. Great job!

This scan only covers files changed in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant