Skip to content

Add a structured outputs lesson to anthropic_api_fundamentals (#161)#164

Open
NishchayMahor wants to merge 1 commit into
anthropics:masterfrom
NishchayMahor:docs/structured-outputs-lesson
Open

Add a structured outputs lesson to anthropic_api_fundamentals (#161)#164
NishchayMahor wants to merge 1 commit into
anthropics:masterfrom
NishchayMahor:docs/structured-outputs-lesson

Conversation

@NishchayMahor

Copy link
Copy Markdown

Refs #161.

The Skilljar "Claude with the Anthropic API" course teaches structured JSON extraction with prefill + `stop_sequences`. Structured outputs (`output_config.format` with a JSON schema) is now the purpose-built solution — constrained decoding means the parse step can't fail and no retry loop is needed — and is explicitly incompatible with assistant prefill, so the two paths don't fit cleanly in one lesson.

This PR doesn't touch Skilljar (that's behind the platform), but it fills the gap in the open-source course material:

  • New `anthropic_api_fundamentals/07_structured_outputs.ipynb` walks through the contact-card extraction case end to end, shows the legacy prefill+stop pattern next to it for comparison, and ends with a multi-meeting extraction exercise.
  • A small table covers when to reach for structured outputs vs. prefill+stop vs. tool use.
  • README updated with the link.

Happy to fold the same content into an updated Skilljar script if that's useful — let me know what the cadence is for keeping the platform version in sync.

What's in the notebook

Cell Content
1 Goals + motivation for structured outputs
2 SDK / client setup (same import block the other lessons use)
3 Contact-card schema
4 `messages.create(... output_config={"format": {"type": "json_schema", "schema": ...}})`
5 Note on prefill incompatibility
6 Legacy prefill + `stop_sequences` for comparison
7 Decision table (which technique for which case)
8 Exercise: extract a list of meetings from a digest

Cells use `claude-sonnet-4-6` to match the GA list from the structured outputs reference.

…pics#161)

The course's older sections cover prefill + stop_sequences and tool use
for JSON extraction. Structured outputs (output_config.format with a JSON
schema) is now the recommended approach because the API uses constrained
decoding — the parse step can't fail and no retry loop is needed. The
Skilljar 'Structured Data' lesson teaches the legacy pattern as primary
and the two are explicitly incompatible (prefill can't be combined with
structured outputs), so the gap is worth filling here too.

New 07_structured_outputs.ipynb walks through the contact-card extraction
case, contrasts it with the legacy prefill+stop pattern, and ends with a
multi-meeting extraction exercise. README updated with the link.
@debbie-shapiro

Copy link
Copy Markdown

I would also add that in order to run through the exercise as designed, it requires an earlier model (sonnet-4-0) which now gives a deprecation message and will no longer be available as of June 14th. The newer models don't work for this part of the course at all.

@NishchayMahor

Copy link
Copy Markdown
Author

Good flag. The new lesson here only uses claude-sonnet-4-6, which is GA for structured outputs, so this notebook itself won't hit the June 14 sonnet-4-0 deprecation.

The exercises still pinned to sonnet-4-0 are really the broader hardcoded-model issue from #71 rather than anything this PR touches. Happy to take that on as a follow-up — sweep the notebooks and bump the deprecated pins — if you point me at which lessons are in scope.

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.

2 participants