Skip to content

Python: [Bug]: PropertySchema.to_json_schema() doesn't recurse into array items — nested "kind" not renamed to "type", nested empty "enum" kept #7198

Description

@exp-ouroborous

Description

PropertySchema.to_json_schema() renames kindtype (and now strips empty enum arrays) only in its top-level properties loop; it does not recurse into nested schemas. For an array property, the nested items schema keeps "kind" and its empty "enum", producing JSON Schema that OpenAI rejects ("schema must have a 'type' key").

Current implementation on main (_models.py#L240-L259 @ 7c6b1e975f75) — the loop touches each prop but never descends into prop["items"] (or nested object properties).

Suggested fix: make the rename + cleanup recursive over items and nested properties. (The top-level empty-enum strip added since 1.0.0b260528 covers half of the old behavior; the nested case is what remains.)

Code Sample

from agent_framework_declarative._models import PropertySchema

schema = PropertySchema.from_dict({
    "properties": {
        "issues": {"kind": "array", "items": {"kind": "string"}},
    }
})
print(schema.to_json_schema())

Actual output — identical on 1.0.0rc2 (latest) and 1.0.0b260528 (nested items unconverted):

{'examples': [], 'strict': False, 'properties': {'issues': {'items': {'kind': 'string', 'enum': []}, 'type': 'array'}}, 'type': 'object'}

Expected:

{'type': 'object', 'properties': {'issues': {'type': 'array', 'items': {'type': 'string'}}}}

Error Messages / Stack Traces

When the resulting schema is sent to OpenAI as a structured-output response_format:

openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema ... 'items' must have a 'type' key", 'type': 'invalid_request_error'}}

Package Versions

agent-framework-declarative==1.0.0rc2 (latest; also reproduced on 1.0.0b260528; non-recursive loop present on main @ 7c6b1e9)

Python Version

3.13

Additional Context

Workaround we use in production: declarative agents whose output schema needs arrays use prompt-instructed JSON instead of outputSchema.

Metadata

Metadata

Assignees

Labels

declarativeUsage: [Issues, PRs], Target: declarative agents and workflowspythonUsage: [Issues, PRs], Target: Python

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions