Skip to main content

normalize_for_strict_validators

Function normalize_for_strict_validators 

Source
pub fn normalize_for_strict_validators(schema: &mut Map<String, Value>)
Expand description

Make a tool input schema acceptable to strict JSON-Schema validators.

OpenAI/Azure (Pydantic-based), Claude thinking models and OpenAI-compatible backends like SGLang reject tool schemas that are valid JSON Schema but omit fields the spec treats as optional. Community-reported failures (OpenCode: “Invalid schema for function ‘lean-ctx_ctx_expand’: None is not of type ‘array’”):

  • type: "object" with properties but no required → clients forward required: null and the backend 400s. We always emit an explicit array.
  • type: "array" without items → “array schema missing items”. We emit a permissive items: {} so the wire schema is self-contained.

Runs recursively over every nested schema position (properties, items, anyOf/oneOf/allOf, object-shaped additionalProperties) so nested definitions get the same guarantees. Existing required arrays are preserved verbatim — this never changes which parameters are mandatory.