{"record":{"id":"6e3dffad4ba83213","repo":"vllm-project/vllm","slug":"tool-choice-function-name-was-not-found-in-the","errorCode":null,"errorMessage":"tool_choice function `{name}` was not found in the available tools","messagePattern":"tool_choice function `(.+?)` was not found in the available tools","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"rust/src/chat/src/error.rs","lineNumber":78,"sourceCode":"    #[error(\"harmony output parsing failed\")]\n    HarmonyOutputParsing {\n        #[source]\n        error: BoxedError,\n    },\n    #[error(\n        \"this model's maximum context length is {max_model_len} tokens, \\\n         but the prompt contains {prompt_len} input tokens\"\n    )]\n    PromptTooLong { max_model_len: u32, prompt_len: u32 },\n    #[error(\"chat request stream `{request_id}` closed before terminal output\")]\n    StreamClosedBeforeTerminalOutput { request_id: String },\n    #[error(\"tool call stream state is inconsistent: {message}\")]\n    ToolCallStreamInvariant { message: String },\n    #[error(\"duplicate tool name `{name}`\")]\n    DuplicateToolName { name: String },\n    #[error(\"tool_choice requires at least one available tool\")]\n    ToolChoiceRequiresTools,\n    #[error(\"tool_choice function `{name}` was not found in the available tools\")]\n    ToolChoiceFunctionNotFound { name: String },\n    #[error(\"failed to build structural tag: {message}\")]\n    StructuralTag { message: String },\n    #[error(transparent)]\n    Text(#[from] vllm_text::Error),\n    #[error(transparent)]\n    Tokenizer(#[from] vllm_tokenizer::TokenizerError),\n}\n\npub type Result<T> = std::result::Result<T, Error>;\n\nimpl Error {\n    /// Whether this error represents invalid user request parameters.\n    pub fn is_request_validation_error(&self) -> bool {\n        match self {\n            Self::PromptTooLong { .. }\n            | Self::DuplicateToolName { .. }\n            | Self::ToolChoiceRequiresTools","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/rust/src/chat/src/error.rs#L60-L96","documentation":"Request validation error (`request.rs:517`): `tool_choice` pins a specific function `name`, but no tool with that name exists in the request's `tools` array. The offending name is carried in the error. Maps to a 4xx at the API boundary (`error.rs:97`).","triggerScenarios":"`{\"tool_choice\": {\"type\": \"function\", \"function\": {\"name\": \"get_weather\"}}, \"tools\": [ ...no get_weather... ]}`; usually a typo or a stale name after a tool was renamed/removed.","commonSituations":"Tool registry drift between client and server; renamed functions during refactors; case mismatches (`GetWeather` vs `get_weather`).","solutions":["Verify the exact spelling/case of the function name against the tools array you are sending.","Assert client-side that the pinned name exists in the tools list before issuing the request.","Regenerate the tool names from a single source of truth (shared constants/registry) instead of string literals."],"exampleFix":"// before\nchoice.function.name = \"get_wether\"; // typo\n\n// after\nchoice.function.name = WEATHER_TOOL_NAME; // shared constant \"get_weather\"","handlingStrategy":"validation","validationCode":"if let Some(ToolChoice::Function { name }) = &request.tool_choice {\n    if !request.tools.iter().any(|t| &t.function.name == name) {\n        return Err(format!(\"tool_choice function `{name}` not in tools\"));\n    }\n}","typeGuard":"fn pinned_tool_exists(choice: Option<&ToolChoice>, tools: &[Tool]) -> bool {\n    match choice {\n        Some(ToolChoice::Function { name }) => tools.iter().any(|t| &t.function.name == name),\n        _ => true,\n    }\n}","tryCatchPattern":"match result {\n    Err(vllm_chat::Error::ToolChoiceFunctionNotFound { name }) => {\n        respond_bad_request(format!(\"unknown tool `{name}` in tool_choice\"))\n    }\n    other => other?,\n}","preventionTips":["Reference tool names through shared constants generated from the tool definitions.","Add a client-side assert that a pinned function exists in the same request's tools array."],"tags":["rust","tool-choice","validation","typo","chat"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}