fix(schema): preserve explicit additionalProperties semantics#113
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces normalization logic for tool inputSchema in src/main.rs to ensure compatibility with OpenAI-style function calls by providing explicit defaults for 'properties', 'required', and 'additionalProperties' fields. Comprehensive unit tests were also added to verify these behaviors. Feedback was provided regarding the efficiency of the map lookups, suggesting a more idiomatic Rust approach using a single entry-based match to avoid redundant operations.
| if schema.get("type").and_then(|t| t.as_str()) == Some("object") { | ||
| let had_properties = schema.get("properties").is_some(); | ||
| schema | ||
| .entry("properties".to_string()) | ||
| .or_insert_with(|| json!({})); | ||
| schema | ||
| .entry("required".to_string()) | ||
| .or_insert_with(|| json!([])); | ||
| if !had_properties { | ||
| schema | ||
| .entry("additionalProperties".to_string()) | ||
| .or_insert_with(|| json!(false)); | ||
| } | ||
| } |
There was a problem hiding this comment.
The normalization logic for inputSchema is correctly implemented to ensure OpenAI compatibility while preserving existing additionalProperties semantics. However, the current implementation performs multiple redundant lookups on the schema map (e.g., get, entry, entry, entry). While not a critical performance bottleneck in this context, combining these into a single entry-based match would be more efficient and idiomatic Rust.
References
- Prefer efficient map access patterns in Rust to avoid redundant lookups and allocations. (link)
|
Sweep update (2026-05-16 UTC): pushed commit What changed:
Validation status:
Next concrete step:
|
40c107f to
fdc418d
Compare
|
Status delta (2026-05-16 UTC): rebased onto and resolved conflict while preserving schema-normalization behavior + strict test assertions.\n\nCurrent state:\n- (conflict gate cleared)\n- branch force-updated to \n\nValidation:\n- remains blocked in this environment by missing linker: \n\nNext concrete step:\n- Let CI run on ; if green, proceed with review/merge. |
|
Superseding prior status comment (shell formatting issue). Status delta (2026-05-16 UTC): rebased Current state:
Validation:
Next concrete step:
|
vish-dini
left a comment
There was a problem hiding this comment.
Change is scoped correctly. Preserves explicit JSON Schema semantics without regressing no-arg normalization, and the regression test covers the boundary that matters.
Summary
properties/required) for OpenAI fn conversion compatibilityadditionalProperties: falsewhen the input schema already declarespropertiesWhy
Current rewrite path over-constrains valid argument schemas by injecting
additionalProperties: falseeven when a tool intentionally leaves default JSON Schema behavior (true). This can reject legitimate payloads.Validation
test_rewrite_tools_list_does_not_force_additional_properties_on_arg_schemaerror: linker \cc` not found`