Repository navigation
fix(routing): serialize Pydantic model classes in QueryStateBuilder - #1242
Open
1828703450qqcom-ux wants to merge 1 commit into
Open
1828703450qqcom-ux wants to merge 1 commit into
1828703450qqcom-ux wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Summary
Fixes
TypeError: BaseModel.model_dump() missing 1 required positional argument: 'self'inQueryStateBuilder.build_for_routing(veadk/routing/state.py) whenLlmRequest.config.response_schemais set to a PydanticBaseModelsubclass.Root Cause
In Google GenAI / ADK (as well as
veadk/runtime/output_state.pyandveadk/models/ark_llm.py),LlmRequest.config.response_schemais commonly populated with a PydanticBaseModelclass (e.g.,class StructuredAnswer(BaseModel): ...).In
veadk/routing/state.py,_jsonable(value)checkedif hasattr(value, "model_dump"):before checking whethervalueis atype. BecauseBaseModel.model_dumpis a regular method on the class,hasattr(StructuredAnswer, "model_dump")evaluates toTrueand calls the unbound methodStructuredAnswer.model_dump(exclude_none=True)withoutself, raisingTypeError.Fix
_jsonable(value)(veadk/routing/state.py), handleisinstance(value, type)first: serialize Pydantic model classes viavalue.model_json_schema()(matchingveadk/models/ark_llm.py), and fall back tovaluefor non-Pydantic types sojson.dumps(..., default=str)renders them safely.test_pydantic_model_class_response_schema_is_rendered_as_json_schemaintests/routing/test_state.py.Verification
pytest tests/routing -q(233 passed)ruff check&ruff format --checkNote: Prepared with AI assistance; reviewed and verified locally.