{"record":{"id":"e55e78f31e71872f","repo":"vllm-project/vllm","slug":"this-model-s-maximum-context-length-is-max-model","errorCode":null,"errorMessage":"this model's maximum context length is {max_model_len} tokens, but the prompt contains {prompt_len} input tokens","messagePattern":"this model's maximum context length is (.+?) tokens, but the prompt contains (.+?) input tokens","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"rust/src/chat/src/error.rs","lineNumber":65,"sourceCode":"    ParserInitialization {\n        kind: &'static str,\n        name: String,\n        #[source]\n        error: BoxedError,\n    },\n    #[error(\n        \"gpt_oss uses native Harmony output parsing; generic {kind} parser override `{selection}` is not supported\"\n    )]\n    HarmonyParserOverrideUnsupported {\n        kind: &'static str,\n        selection: String,\n    },\n    #[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),","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/rust/src/chat/src/error.rs#L47-L83","documentation":"Classic context-length rejection: the tokenized prompt (`prompt_len`) exceeds the model's configured `max_model_len` (u32 token counts carried in the error). Thrown by the chat layer during request validation before scheduling; `error.rs:94` classifies it in `is_request_validation_error()` as a user-request error, so it maps to an HTTP 4xx at the API boundary rather than a server fault.","triggerScenarios":"Sending a chat request whose messages tokenize to more tokens than `max_model_len`; includes tokenizer-added special tokens and chat template overhead, so a prompt sized exactly to the limit can still fail.","commonSituations":"Large pasted documents or long conversation histories; retrieval-augmented prompts stuffing too many chunks; images/multimodal content consuming the budget; `--max-model-len` set lower than what client code assumes.","solutions":["Client-side: truncate or summarize the conversation so tokenized prompt < max_model_len (leave headroom for output tokens).","Count tokens with the same tokenizer the server uses before sending (including chat-template overhead).","Server-side: raise `max_model_len` in the engine config if the model's native context supports it.","Enable/keep automatic prefix caching so repeated long prefixes are not re-billed, letting you trim history safely."],"exampleFix":"// before\nlet messages = full_history; // 200k tokens, max_model_len = 128k\n\n// after\nlet messages = trim_to_token_budget(full_history, max_model_len - reserved_output);","handlingStrategy":"validation","validationCode":"let prompt_len = tokenizer.count_chat_tokens(&request)?;\nif prompt_len + request.max_tokens.unwrap_or(16) > max_model_len as usize {\n    return Err(TrimHistory(prompt_len, max_model_len));\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(vllm_chat::Error::PromptTooLong { max_model_len, prompt_len }) => {\n        // 4xx to the client, never a 500\n        respond_json(StatusCode::BAD_REQUEST, json!({\n            \"error\": \"prompt too long\",\n            \"max_model_len\": max_model_len,\n            \"prompt_len\": prompt_len\n        }))\n    }\n    other => other?,\n}","preventionTips":["Token-count every prompt with the server's tokenizer before sending; include chat-template overhead.","Keep conversation histories under a budget of max_model_len minus reserved output tokens.","Expose max_model_len in your API error payload so clients can self-correct."],"tags":["rust","context-length","validation","tokenizer","chat"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}