Skip to content

fix(gen): Enforce extra=forbid as default and overwrite with extra=allow for response validation - #240

Draft
mwien wants to merge 1 commit into
mainfrom
allow-extra-response-fields
Draft

mwien wants to merge 1 commit into
mainfrom
allow-extra-response-fields

Conversation

@mwien

@mwien mwien commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Context

Closes SAP/ai-sdk-python-backlog#95.

What this PR does and why it is needed

  • Makes extra=forbid (rejecting unknown fields during validation) the consistent default behaviour throughout the gen package
  • Overwrites extra=allow for all response related validations
  • Cleans up tests for this behaviour by grouping them in one location.

Notes:

  • Because some models are used in both requests and responses, it is not possible to achieve this behaviour by purely configuring model classes. Instead model classes are configured consistently with extra=forbid and helpers for response validation are provided that set extra=allow which overwrites the model configs. If there are better ways to achiever this, I'm happy for suggestions.
  • The custom base model and helpers currently lie in gen_ai_hub/_base_model.py. Maybe there is a better place?
  • Because extra=forbid is now set throughout the code base (as well as the model_dump override that sets by_alias and exclude_none, we need to make sure this breaks no clients.
  • The PR is not yet e2e tested (will do that once the pipeline is green again).

Definition of Done

  • Code is tested (Unit, Integration, E2E)
  • Error handling created / updated & covered by the tests above
  • Documentation updated
    • Only Public APIs are allowed to be used in documentation/tutorials/sample code
  • (Optional) Aligned changes with the JS/TS and Java SDK
  • (Optional) Release notes updated -->

@mwien mwien changed the title chore: enforce extra=forbid in all models except for response validation chore: Enforce extra=forbid as default and overwrite with extra=allow for response validation Nov 24, 2026
@mwien mwien changed the title chore: Enforce extra=forbid as default and overwrite with extra=allow for response validation fix: Enforce extra=forbid as default and overwrite with extra=allow for response validation Nov 26, 2026
@mwien mwien changed the title fix: Enforce extra=forbid as default and overwrite with extra=allow for response validation fix(gen): Enforce extra=forbid as default and overwrite with extra=allow for response validation Nov 26, 2026

This branch has not been deployed

No deployments
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