Sanitize Gemini tool-parameter schemas#51
Conversation
Greptile SummaryThis PR sanitizes tool parameter schemas before forwarding them to the Vertex/Gemini API, which rejects JSON Schema keywords it does not recognize. Both the chat-completions (
Confidence Score: 5/5Safe to merge — the change is purely additive sanitization applied before parameters reach the Vertex wire format, with no effect on any other code path. The sanitization pipeline is logically correct: ref inlining runs before the allowlist strip, recursive schemas are detected via the active stack and degraded gracefully, and sibling schema-valued keywords are themselves passed through resolve_refs before being merged. Both changed call-sites are covered by the new tests, including the previously-flagged sibling-anyOf case. No existing behavior is altered for schemas that were already clean. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["tool.function.parameters\n(Option<Value>)"] --> B["sanitized_parameters()"]
B --> C{"is Some?"}
C -- No --> Z["None → passed to Vertex"]
C -- Yes --> D["inline_schema_refs()"]
D --> D1["lift root $defs / definitions\ninto lookup table"]
D1 --> D2["resolve_refs() — recursive"]
D2 --> D3{"has $ref?"}
D3 -- No --> D4["recurse into all child values"]
D3 -- Yes --> D5{"name in active stack?"}
D5 -- Yes/cycle --> D6["substitute {type: object}"]
D5 -- No/found --> D7["clone target, push active,\nresolve_refs target, pop active"]
D5 -- No/not found or non-local --> D6
D7 --> D8["resolve each sibling via resolve_refs,\nor_insert into resolved target"]
D8 --> D9["*value = replacement"]
D6 --> D9
D4 --> E["retain_supported_keys()"]
D9 --> E
E --> E1["map.retain — drop keys not in allowlist"]
E1 --> E2["recurse into properties values"]
E2 --> E3["recurse into items (object or array)"]
E3 --> E4["recurse into anyOf variants"]
E4 --> Z2["sanitized Value → passed to Vertex"]
Reviews (3): Last reviewed commit: "Review fixes" | Re-trigger Greptile |
No description provided.