#10248·agno

[Bug] get_json_schema does not unwrap PEP 604 optional types

Author: MohammadHijjawi97Created Sep 17, 2026Updated Sep 17, 2026

Description

get_json_schema unwraps Optional[T] (typing.Union) before building the property schema, so Optional[int] becomes {"type": "integer"}. PEP 604 int | None uses types.UnionType, which the type_origin is Union check misses. The parameter is left as anyOf instead of matching Optional[int].

Steps to Reproduce

python
from agno.utils.json_schema import get_json_schema

print(get_json_schema({"count": int | None}))
print(get_json_schema({"count": Optional[int]}))  # from typing import Optional

Expected Behavior

Both forms unwrap to {"type": "integer"}.

Actual Behavior

Optional[int] is {"type": "integer"}. int | None is {"anyOf": [{"type": "integer"}, {"type": "null"}]}.

Environment

  • OS: Windows 11
  • Agno Version: v3.0.10 (current main)
  • Additional Environment Details: Python 3.13

Possible Solutions (optional)

Use the existing is_origin_union_type helper when detecting optionals.