Fix tool schema constraints dropped during OCI conversion (breaks MCP + Gemini) #109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug
convert_to_oci_toolstrips JSON Schema constraints (enum, min/max, pattern, format) from tool definitions before sending them to the model. A tool defined withenum: ["cpu", "memory", "disk", "network"]gets reduced to justtype: string— the model never sees the allowed values.Additionally, Optional fields (Pydantic
anyOfpattern) get converted totype: "any"which is not valid JSON Schema — this causes Gemini models to return 400 errors.Root cause: the old code uses
tool.argswhich goes through Pydantic'stool_call_schemare-generation, then only keepstypeanddescription:Reproduction
Tool with
enum: ["cpu", "memory", "disk", "network"], prompt: "Check the latency metrics" (intentionally not in enum).main branch (broken) — enum stripped, models hallucinate or crash:
fix branch — enum preserved, models respect constraints:
MCP tool reproduction
Same test with a FastMCP server (
MetricNameenum +duration_hourswithge=1, le=168).main branch — MCP tools broken on Gemini, hallucinated on Llama:
fix branch — MCP tools work correctly:
Fix
args_schema.model_json_schema()instead oftool.argsto get the original schema with constraints intact_sanitize_tool_property()filters through an allowlist of standard JSON Schema keys (enum, format, min/max, pattern, items, etc.) and resolves Pydantic v2anyOfpatterns forOptional[T]_enrich_description()embeds constraints into the description string since CohereParameterDefinition only supports type/description/is_requiredTests
_sanitize_tool_property(enum, format, ranges, patterns, nested objects, anyOf resolution, MCP round-trips)