Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/routing/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,23 @@ def test_tool_declarations_are_rendered_as_stable_json():
)
payload = json.loads(segment.split("\n", 1)[1].split("\n[user]", 1)[0])
assert payload[0]["function_declarations"][0]["name"] == "lookup"


def test_pydantic_model_class_response_schema_is_rendered_as_json_schema():
from pydantic import BaseModel

class StructuredAnswer(BaseModel):
verdict: str
score: int

request = make_request(("user", "grade this"))
request.config = types.GenerateContentConfig(response_schema=StructuredAnswer)

state = QueryStateBuilder(defuse=False).build_for_routing(request)
segment = next(
part["text"] for part in state if part["text"].startswith("[response_schema]\n")
)
payload = json.loads(segment.split("\n", 1)[1].split("\n[user]", 1)[0])
assert payload["title"] == "StructuredAnswer"
assert payload["properties"]["verdict"]["type"] == "string"
assert payload["properties"]["score"]["type"] == "integer"
4 changes: 4 additions & 0 deletions veadk/routing/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@


def _jsonable(value: Any) -> Any:
if isinstance(value, type):
if callable(getattr(value, "model_json_schema", None)):
return value.model_json_schema()
return value
if hasattr(value, "model_dump"):
return value.model_dump(exclude_none=True)
if isinstance(value, (list, tuple)):
Expand Down