Skip to content

fix(routing): serialize Pydantic model classes in QueryStateBuilder - #1242

Open
1828703450qqcom-ux wants to merge 1 commit into
volcengine:mainfrom
1828703450qqcom-ux:fix/routing-pydantic-response-schema
Open

1828703450qqcom-ux wants to merge 1 commit into
volcengine:mainfrom
1828703450qqcom-ux:fix/routing-pydantic-response-schema

Conversation

@1828703450qqcom-ux

Copy link
Copy Markdown

Summary

Fixes TypeError: BaseModel.model_dump() missing 1 required positional argument: 'self' in QueryStateBuilder.build_for_routing (veadk/routing/state.py) when LlmRequest.config.response_schema is set to a Pydantic BaseModel subclass.

Root Cause

In Google GenAI / ADK (as well as veadk/runtime/output_state.py and veadk/models/ark_llm.py), LlmRequest.config.response_schema is commonly populated with a Pydantic BaseModel class (e.g., class StructuredAnswer(BaseModel): ...).

In veadk/routing/state.py, _jsonable(value) checked if hasattr(value, "model_dump"): before checking whether value is a type. Because BaseModel.model_dump is a regular method on the class, hasattr(StructuredAnswer, "model_dump") evaluates to True and calls the unbound method StructuredAnswer.model_dump(exclude_none=True) without self, raising TypeError.

Fix

  • In _jsonable(value) (veadk/routing/state.py), handle isinstance(value, type) first: serialize Pydantic model classes via value.model_json_schema() (matching veadk/models/ark_llm.py), and fall back to value for non-Pydantic types so json.dumps(..., default=str) renders them safely.
  • Add regression test test_pydantic_model_class_response_schema_is_rendered_as_json_schema in tests/routing/test_state.py.

Verification

  • pytest tests/routing -q (233 passed)
  • ruff check & ruff format --check

Note: Prepared with AI assistance; reviewed and verified locally.

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