Adala icon indicating copy to clipboard operation
Adala copied to clipboard

JSON Schema converter treats optional properties as required

Open yaodong-shen opened this issue 4 months ago • 0 comments

Problem

json_schema_to_model() ignores the schema required array and passes Field(...) for every property. As a result, properties that JSON Schema allows callers to omit are rejected by the generated Pydantic model.

Reproduction

Using a schema with required_name in required and optional_note omitted from required:

Model = json_schema_to_model({
    "type": "object",
    "properties": {
        "required_name": {"type": "string"},
        "optional_note": {"type": "string"},
    },
    "required": ["required_name"],
})
Model(required_name="ok")

Current result:

ValidationError: optional_note - Field required

Both generated fields report is_required() == True.

Expected behavior

Only fields named in the JSON Schema required array should be mandatory. Optional fields should remain omittable, while explicit null should still be rejected unless the property schema permits null. The field-schema helper used for skill outputs can continue marking all of its supplied fields as required for backward compatibility.

yaodong-shen avatar Jul 27 '26 04:07 yaodong-shen