#10256·agno

[Bug] dataclass Optional[List] schema drops items when flattening anyOf

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

Description

When get_json_schema_for_arg flattens an optional dataclass field, it copies only schema["type"] from the non-null anyOf branch and drops the rest. Optional[List[str]] becomes {"type": "array"} with no items. Nested object fields lose properties.

Steps to Reproduce

python
from dataclasses import dataclass
from typing import List, Optional

from agno.utils.json_schema import get_json_schema_for_arg

@dataclass
class Profile:
    tags: Optional[List[str]] = None

print(get_json_schema_for_arg(Profile)["properties"]["tags"])

Expected Behavior

{"type": "array", "items": {"type": "string"}}

Actual Behavior

{"type": "array"} with items missing.

Environment

  • OS: Windows 11
  • Agno Version: current main
  • Additional Environment Details: Python 3.13

Possible Solutions (optional)

Copy the full non-null anyOf schema instead of only the type key.