feat(python-codegen): forbid extra fields on template.prompt payloads#27
Merged
Conversation
A `template.prompt` payload is the render INPUT — a strict contract — so its generated Pydantic model now carries `model_config = ConfigDict(extra="forbid")`. Passing a mistyped slot (e.g. `WelcomePromptPayload(naem=...)`) now raises `ValidationError` at construction instead of being silently dropped and rendered blank. Scoped to `template.prompt` only: `template.output` / `template.toolcall` payloads are parse targets (an LLM/parsed payload may carry extra fields), so they keep the tolerant default (`extra="ignore"`). Injected post-emit in `render_payload_vo`, so the overridable `_emit_payload_class` extension seam is untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A
template.promptpayload is the render input — a strict contract. Its generated Pydantic model now carries:So a mistyped slot raises at construction instead of silently rendering blank:
Scope
Only
template.prompt.template.output/template.toolcallpayloads are parse targets — an LLM/parsed payload may legitimately carry extra fields — so they keep the tolerant default (extra="ignore"). Verified both ways in the spike and the test.Injected post-emit in
render_payload_vo, so the overridable_emit_payload_classextension seam is untouched (back-compat).Tests
test_template_prompt_payload_forbids_extra_fields— asserts the prompt payload emitsConfigDict(extra="forbid")+ imports it, the output payload does not, and the emitted prompt model actually raises on an unknown field at runtime. Full codegen + conformance suite green (510).🤖 Generated with Claude Code