Skip to content

feat(python-codegen): forbid extra fields on template.prompt payloads#27

Merged
dmealing merged 1 commit into
mainfrom
feat/py-strict-prompt-payloads
Jun 15, 2026
Merged

feat(python-codegen): forbid extra fields on template.prompt payloads#27
dmealing merged 1 commit into
mainfrom
feat/py-strict-prompt-payloads

Conversation

@dmealing

Copy link
Copy Markdown
Member

What

A template.prompt payload is the render input — a strict contract. Its generated Pydantic model now carries:

class WelcomePromptPayload(BaseModel):
    model_config = ConfigDict(extra="forbid")
    name: str | None = None

So a mistyped slot raises at construction instead of silently rendering blank:

WelcomePromptPayload(naem="Ada")   # -> pydantic.ValidationError (was: silently dropped)

Scope

Only template.prompt. template.output / template.toolcall payloads 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_class extension seam is untouched (back-compat).

Tests

test_template_prompt_payload_forbids_extra_fields — asserts the prompt payload emits ConfigDict(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

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>
@dmealing
dmealing merged commit 5068502 into main Jun 15, 2026
29 checks passed
@dmealing
dmealing deleted the feat/py-strict-prompt-payloads branch June 15, 2026 00:30
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