Skip to content

refactor(py): rename OutputConfig.schema_ to json_schema, pin wire alias - #6024

Open
huangjeff5 wants to merge 1 commit into
mainfrom
refactor/outputconfig-json-schema
Open

refactor(py): rename OutputConfig.schema_ to json_schema, pin wire alias#6024
huangjeff5 wants to merge 1 commit into
mainfrom
refactor/outputconfig-json-schema

Conversation

@huangjeff5

Copy link
Copy Markdown
Contributor

Product Context & Motivation

In the Genkit Python SDK, structured output configuration had inconsistent field naming: GenerateActionOutputConfig used json_schema, whereas OutputConfig used schema_ to avoid shadowing Pydantic's BaseModel.schema. This inconsistency required linter warning suppressions (filterwarnings) and created friction for developers interacting with output schemas in Python code.

This PR renames OutputConfig.schema_ to json_schema in Python while pinning the serialization alias to schema. Developers get a clean, consistent Python API (config.json_schema), while Genkit's cross-language wire protocol (Dev UI, reflection server, TS/Go SDKs) continues to send and receive "schema" with 100% wire fidelity.

Key Changes

  • Renamed Python field OutputConfig.schema_ to json_schema.
  • Configured Pydantic field aliases: validation_alias=AliasChoices('json_schema', 'schema') (accepts both input names) and serialization_alias='schema' (serializes wire key as "schema").
  • Updated code generator (schema_to_typing.py) to emit the new alias configuration cleanly.
  • Removed legacy warnings.filterwarnings hacks.

Verification & Safety

  • 100% backward compatible: input validation accepts both json_schema and schema. Wire payloads remain identical.
  • Verified with full core suite pytest py/packages/genkit/tests/genkit/ (799 passed).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the OutputConfig model to use json_schema instead of schema_ to avoid shadowing the parent BaseModel.schema attribute. It leverages Pydantic's AliasChoices for validation and serialization aliases to maintain compatibility with the wire format, allowing the removal of warning filters. The schema generation script schema_to_typing.py has been updated accordingly. There are no review comments, so no additional feedback is provided.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant