responses: custom tools (free-form input + grammar) are rejected or silently downgraded on upstreams that accept only strict function schemas
Is it a request payload issue? [ ] Yes, this is a request payload issue. I am using a client/cURL to send a request payload, but I received an unexpected error. [x] No, it's another issue.
If it's a request payload issue, you MUST know N/A — the payload is a valid Responses request. The upstream rejects it because it only accepts strict function schemas.
Describe the bug
Summary
custom tools carry free-form string input and may be constrained by a grammar. Neither shape maps onto a JSON Schema function tool, so on any upstream that accepts only strict function schemas the request is rejected outright, and on upstreams that tolerate it the model's free-form call comes back as a malformed function_call. There is also no safe lossy mode: stripping the declarations silently removes a capability the client believes it has, while forcing a stripped tool to be called must fail rather than quietly call something else.
Observed behavior
- An upstream that validates
type: "custom"rejects the request with a schema error, or drops the declaration and the model then answers a question it was never given the tool for. - A
custom_tool_callreturned by the model is not recognized on a non-bridged path, so the call never reaches the client as a tool call it can answer — and a matchingcustom_tool_call_output, if the client sends one, is consumed by nothing. Exactly how a given upstream renders this (text block, dropped, or rejected) varies and is not pinned down here. - A grammar constraint (the
syntax/definitionpayload) has no representation a strict function schema can hold. Silently dropping it leaves the model unconstrained while the client believes it is constrained — the worst possible failure, because it is invisible. - Two different tools that share a display name (one custom, one ordinary function) collide when flattened, so a bridged call can be attributed to the wrong tool.
Root cause chain
internal/translator/*converts tool declarations to the target format structurally; acustomdeclaration either has no mapping or an incorrect one.custom_tool_call/custom_tool_call_outputare separate item types with no conversion to and from thefunction/function_call_outputpair.- Nothing tracks which declared tools are custom, so declarations, history, the model's call, and the client's result cannot be matched back to the same tool.
- Grammar payloads have no fallback that preserves the constraint's intent without pretending to enforce it upstream.
CLI Type
All providers whose upstream does not natively accept the Responses tool surface. meta is the known hard case today: it rejects type: custom outright.
Model Name Any.
LLM Client
Codex-style clients declaring custom tools, with or without a grammar.
Request Information
Declaration, the model's call, and the client's result — three shapes with no strict-schema equivalent:
{ "type": "custom", "name": "apply_patch",
"description": "Apply a patch",
"format": { "type": "grammar", "syntax": "lark", "definition": "start: /.+" } }
{ "type": "custom_tool_call", "call_id": "call_1", "name": "apply_patch", "input": "*** Begin Patch" }
{ "type": "custom_tool_call_output", "call_id": "call_1", "output": "Done!" }Expected behavior
- A custom declaration is wrapped as a function carrying exactly one string parameter that transports the original input, and the call is unwrapped back to a
custom_tool_callwith the original input intact. - The wrapper alias is deterministic, derived from namespace + name + kind, so the same tool gets the same alias in every round and across turns. A function and a custom tool that share a display name never share an alias, and no name already assigned to a non-custom function is ever reused.
- Grammar payloads are described, never silently dropped, when the route opts into grammar description: the syntax is folded into the tool description and it is stated plainly that the constraint is not enforced upstream.
- Stripping is available as an explicit lossy mode and is honest about it: future declarations are removed, but convertible history is kept — a prior
custom_tool_callbecomes afunction_callcarrying{"input": <original>}, and its output becomes afunction_call_output. A non-string historical input fails instead of inventing a payload. - A forced custom choice (
tool_choicenaming a stripped tool) fails with 422. So does a custom contract on arejectroute, and adisabledsearch route. Nothing is silently downgraded.
Screenshots N/A.
OS Type
- OS: macOS
- Version: 26.x / arm64 (not platform specific)
Additional context
Scope in this issue
- One bridge object per attempt, built from the request contract (declarations plus the alias map) so request, history, response, and stream recovery all share a single mapping. It is built before request rewriting with the set of already-reserved function names, so a collision is impossible by construction.
- Declaration rewriting: wrap every custom declaration reachable from
tools, nested namespaces, andadditional_toolsinputs, including inside a namespace. - History:
ConvertCustomHistorykeeps prior client-executed custom calls in the conversation when their declarations are stripped for a strict upstream. StripCustomDeclarations: remove future declarations, keep convertible history, and fail a forced choice rather than silently changing which tool the model must call.- Response and stream recovery: resolve only generated wire aliases back to a custom identity. A display name is useful while translating client history but is not unique enough to classify an upstream
function_call— an ordinary function must never be mistaken for a custom tool, so an ambiguous name resolves to nothing and the call is left untouched. - Grammar modes:
reject(default) anddescribe(function mode only).
Out of scope
tool_search discovery, schema portability for strict upstreams, budget accounting, and capability advertisement.
Invariants
- Unknown names never resolve. Ambiguity is an error, not a coin flip.
- Grammar is never dropped without being described.
- The lossy modes are opt-in and their loss is always explicit, in the response to the client or as a 422 — never a silent capability loss.
Related issues
Depends on the contract/identity representation and the route policy surface. Pairs with the portable-tool-surface issue for upstreams such as meta that need both adaptations together.
Source: router-for-me/CLIProxyAPI