Skip to content

LlmAgent output_schema silently becomes an empty Schema() for Literal and Annotated types #7927

Description

@sumedh-aerram

🔴 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:

  1. pip install google-adk (reproduced on current main, 95d8610)
  2. 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):

  1. In utils/_schema_utils.py, wrap SchemaType with a pydantic wrap validator that returns Literal/Annotated aliases unchanged and defers everything else to the existing union validation. That fixes all four fields in one place.
  2. In LlmRequest.set_output_schema, send such aliases as response_json_schema using the existing schema_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

  1. added a commit that references this issue on Nov 1, 2026
    5a3da60
  2. sumedh-aerram commented on Nov 2, 2026

    @sumedh-aerram
    Author

    Thanks for triaging! For reference, a fix for this is up in #7928: it keeps Literal/Annotated aliases on all four SchemaType fields, sends them to Gemini as response_json_schema, and lets the native Anthropic adapter use that JSON schema. Happy to adjust the approach if you'd prefer something different.

  3. added
    core[Component] This issue is related to the core interface and implementation
    on Nov 5, 2026
  4. added theissue type on Nov 5, 2026
  5. llalitkumarrr commented on Nov 5, 2026

    @llalitkumarrr
    Collaborator

    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.

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

Metadata

Metadata

Assignees

Labels

core[Component] This issue is related to the core interface and implementation

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions