Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
tools: Ensure `properties` always exists in JSON Schema (#34015)
Oleksiy Syvokon966e75b61097
diff --git a/crates/assistant_tool/src/tool_schema.rs b/crates/assistant_tool/src/tool_schema.rsindex 001b16ac87f..7b48f93ba6d 100644--- a/crates/assistant_tool/src/tool_schema.rs+++ b/crates/assistant_tool/src/tool_schema.rs@@ -25,10 +25,15 @@ fn preprocess_json_schema(json: &mut Value) -> Result<()> {// `additionalProperties` defaults to `false` unless explicitly specified.// This prevents models from hallucinating tool parameters.if let Value::Object(obj) = json {- if let Some(Value::String(type_str)) = obj.get("type") {- if type_str == "object" && !obj.contains_key("additionalProperties") {+ if matches!(obj.get("type"), Some(Value::String(s)) if s == "object") {+ if !obj.contains_key("additionalProperties") {obj.insert("additionalProperties".to_string(), Value::Bool(false));}++ // OpenAI API requires non-missing `properties`+ if !obj.contains_key("properties") {+ obj.insert("properties".to_string(), Value::Object(Default::default()));+ }}}Ok(())