Repository navigation
Description
🔴 Required Information
Describe the Bug:
LlmAgent(output_schema=...) accepts a Literal[...] or an Annotated[...] type, but silently replaces it with an empty types.Schema(). No error or warning is raised, and the model then gets no usable response schema.
SchemaType is types.SchemaUnion. Neither typing.Literal nor typing.Annotated aliases match its alias members, and types.Schema is configured with from_attributes=True, so pydantic coerces the alias object into a Schema with every field unset. BaseNode.input_schema, BaseNode.output_schema and RequestInput.response_schema share the same type and the same behavior.
Steps to Reproduce:
pip install google-adk(reproduced on currentmain, 95d8610)- Run:
from typing import Annotated, Literal
from pydantic import BaseModel, Field
from google.adk.agents import LlmAgent
class Answer(BaseModel):
text: str
for schema in (
Literal["yes", "no"],
Annotated[Answer, Field(description="The answer")],
Annotated[int, Field(gt=0)],
):
print(LlmAgent(name="a", model="gemini-2.5-flash", output_schema=schema).output_schema)Expected Behavior:
The schema is kept as given, as already happens for Answer, list[Answer] and int. ADK's own helpers already handle these types: schema_to_json_schema turns Literal["yes", "no"] into {"type": "string", "enum": ["yes", "no"]}, and SetModelResponseTool builds a correct declaration for them.
Observed Behavior:
All three print an empty schema (additional_properties=None defs=None ... type=None), i.e. types.Schema().
Simply keeping the value is not enough on its own: LlmRequest.set_output_schema stores it in config.response_schema, and google-genai's t_schema raises ValueError: Unsupported schema type for these aliases. So these schemas would need to be sent as response_json_schema (via schema_to_json_schema) instead.
Environment Details:
- ADK Library Version: main @ 95d8610
- Desktop OS: macOS
- Python Version: 3.11 (google-genai 2.34.0, pydantic 2.14.2)
Model Information:
- Are you using LiteLLM: No
- Which model is being used: gemini-2.5-flash (bug occurs at agent construction, before any model call)
🟡 Optional Information
Proposed fix (I'm working on it):
- In
utils/_schema_utils.py, wrapSchemaTypewith a pydantic wrap validator that returnsLiteral/Annotatedaliases unchanged and defers everything else to the existing union validation. That fixes all four fields in one place. - In
LlmRequest.set_output_schema, send such aliases asresponse_json_schemausing the existingschema_to_json_schema.
Maintainers: would you prefer the shared SchemaType fix, or a validator limited to LlmAgent.output_schema? Enforcing Literal/Field constraints in validate_schema is out of scope here, since it overlaps #7280 / #7285.
Activity
fix(models): use response_json_schema for Anthropic structured output
sumedh-aerram commentedon Nov 2, 2026
Thanks for triaging! For reference, a fix for this is up in #7928: it keeps
Literal/Annotatedaliases on all fourSchemaTypefields, sends them to Gemini asresponse_json_schema, and lets the native Anthropic adapter use that JSON schema. Happy to adjust the approach if you'd prefer something different.llalitkumarrr commentedon Nov 5, 2026
Hello @sumedh-aerram,
Thank you for raising this issue and for your contribution. Your PR is currently under review and will be merged once the changes are approved, we appreciate your patience in the meantime.