fix: enforce OpenAI tool-choice contract - #650
Draft
waw2637 wants to merge 4 commits into
Draft
Conversation
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.
Summary
tool_choicemodes (none,auto,required, named function, andallowed_tools) andparallel_tool_callsstream_options.include_usageCloses #649
Why
FastFlowLM 0.9.46 could return HTTP 200 with
finish_reason: "tool_calls"even when a truncated model response produced an empty or undeclared function name or malformed arguments. This was reproduced across Gemma 4, Qwen 3, and Qwen 3.5. Clients then attempted to dispatch calls that were not usable.The REST boundary now treats the model/parser output as untrusted and validates it against the request contract before exposing it to clients.
Supported contract
/v1/chat/completionstool_choice:none,auto,required, named function, andallowed_toolsparallel_tool_callsExplicit limitations
strict: trueis rejected because constrained JSON Schema decoding is not implementedVerification
Build and unit tests
flmtarget successfully (96 build steps)openai_tool_policy_contractpassedLive NPU contract matrix
All models were loaded and tested serially with the binary built from
11c4081.tool_choice: nonetool_choice: requiredallowed_toolsrequired subsetThe recovery test deliberately truncates a required call with
max_tokens: 1, expects a structured HTTP 500 model error, and immediately sends a valid required call to verify that rejected state is not reused.Related reports
These can improve how often a model generates a valid call, while this PR protects the API boundary when it does not.
Review requested
This PR is intentionally draft until independent review confirms the contract and test coverage.