Repository navigation
fix(llm): keep the chat working when a tool schema uses true or false - #1148
Draft
sosidudku1 wants to merge 2 commits into
Draft
sosidudku1 wants to merge 2 commits into
sosidudku1 wants to merge 2 commits into
Conversation
… server rejects
LM Studio and llama.cpp refuse the whole chat request when one tool's
JSON Schema holds a boolean subschema ("evidence": true), answering
'JSON schema error at #/...: schema must be an object' (ATO-1399).
- normalize boolean subschemas in every OpenAI-compatible tools array
(true -> {}, false -> dropped property/branch or { not: {} });
additionalProperties and friends keep their boolean values, and tools
with nothing to rewrite stay byte-identical
- treat a schema error as non-retryable instead of three blind 5xx tries
- when the error's JSON pointer names exactly one tool, resend once
without it (unary and stream) and log a warning naming the tool
- give the leftover case its own user-facing sentence
…l schema error - items: false next to prefixItems now caps maxItems at the tuple length (or a tighter existing maxItems) instead of 0 - when the resend without the rejected tool also fails before output, the first (schema) error is thrown in both unary and stream paths
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
A user connected LM Studio as an OpenAI-compatible provider, and every turn failed with:
JSON schema error at #/$defs/RecordSource/oneOf/1/properties/evidence: schema must be an objectOne of their MCP or plugin tools uses a boolean subschema (
"evidence": true). That is valid JSON Schema, but LM Studio and llama.cpp reject it, so the whole request failed, not just that tool.Now:
truebecomes{}or is dropped where the keyword is optional.falsedrops the property (and itsrequiredentry) or theanyOf/oneOfbranch, capsmaxItemsforitems(at theprefixItemslength when there is a tuple, 0 otherwise), and becomes{ not: {} }elsewhere.additionalPropertiesand similar keywords keep their boolean values. The input is never mutated, and a tools array with nothing to rewrite is sent byte-identical to before.replyandfinishare never dropped. If no single tool matches, the original error goes back. If the resend fails too before any output, the first (schema) error is thrown, not the resend's.Why
One badly-shaped third-party tool should not break the whole chat.
Known gaps
{ not: {} }(only for afalsethat cannot be dropped, which is rare) may not be understood by every local server.openai-provider.tsgrew from 1023 to 1096 lines.Merge note
Conflicts with #1123 in
openai-provider.ts. #1123 is expected to merge first; when this branch is updated after it, keeplearnTemperature(request, err, body),activeRequest, and #1123'ssentBodyin the unary wrapper.Tests
tool-schema-booleans.test.ts: the exact$defs/RecordSource/oneOf/1/properties/evidence: truecase, the other rewrite rules, no mutation, same reference when nothing changes, body builder applies it.tool-schema-rejection.test.ts: pointer matching, including ambiguous, missing and reply/finish cases.openai-tool-schema-retry.test.ts: resend without the tool (unary and stream, exactly two fetches), an unmatched error surfacing after one fetch, at most one drop, the new user-facing sentence, and a failed resend surfacing the first schema error (500 then 400).tool-schema-booleans.test.tsalso coversprefixItems+items: falsekeeping the tuple satisfiable.Fixes ATO-1399.
Not yet checked on the second Mac.