{"record":{"id":"6e53343fe4a60b1f","repo":"vllm-project/vllm","slug":"when-both-logprobs-and-logprob-token-ids-are-set","errorCode":null,"errorMessage":"when both logprobs and logprob_token_ids are set, logprobs must equal len(logprob_token_ids). Got logprobs={logprobs}, len(logprob_token_ids)={num_token_ids}.","messagePattern":"when both logprobs and logprob_token_ids are set, logprobs must equal len\\(logprob_token_ids\\)\\. Got logprobs=(.+?), len\\(logprob_token_ids\\)=(.+?)\\.","errorType":"validation","errorClass":"LogprobsError","httpStatus":400,"severity":"error","filePath":"rust/src/text/src/lower/logprobs.rs","lineNumber":33,"sourceCode":"    #[error(\"{parameter} must be non-negative or -1, got {value}\")]\n    InvalidCount { parameter: &'static str, value: i32 },\n    #[error(\n        \"requested {parameter} of {requested}, which is greater than max allowed: {max_allowed}\"\n    )]\n    TooManyCount {\n        parameter: &'static str,\n        requested: usize,\n        max_allowed: usize,\n    },\n    #[error(\n        \"requested logprob_token_ids of length {requested}, \\\n         which is greater than max allowed: {max_allowed}\"\n    )]\n    TooManyTokenIds {\n        requested: usize,\n        max_allowed: usize,\n    },\n    #[error(\n        \"when both logprobs and logprob_token_ids are set, logprobs must equal \\\n         len(logprob_token_ids). Got logprobs={logprobs}, len(logprob_token_ids)={num_token_ids}.\"\n    )]\n    TokenIdsMismatch { logprobs: i32, num_token_ids: usize },\n}\n\n/// Validate logprobs count sampling parameters.\npub(super) fn validate_logprobs(\n    logprobs: Option<i32>,\n    prompt_logprobs: Option<i32>,\n    logprob_token_ids: Option<&[u32]>,\n    sampling_limits: SamplingLimits,\n) -> Result<(), LogprobsError> {\n    let vocab_size = sampling_limits.model_vocab_size;\n    let max_logprobs =\n        normalize_logprobs_count(sampling_limits.max_logprobs, vocab_size, \"max_logprobs\")?;\n\n    validate_logprobs_count(logprobs, max_logprobs, vocab_size, \"logprobs\")?;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/rust/src/text/src/lower/logprobs.rs#L15-L51","documentation":"When both `logprobs` and `logprob_token_ids` are present in a request, the Rust frontend requires `logprobs == len(logprob_token_ids)` (rust/src/text/src/lower/logprobs.rs:94-101), matching the Python API contract that the count parameter describes exactly how many per-position logprobs are returned.","triggerScenarios":"Sending e.g. `logprobs: 5` together with a `logprob_token_ids` array of length 3 (any mismatch triggers it).","commonSituations":"Independently tuning two fields that must agree; patching requests in middleware that updates one field but not the other; migrating from an API that allowed them to differ.","solutions":["Set logprobs to exactly len(logprob_token_ids)","Or drop one of the two fields: omitting logprobs skips the check"],"exampleFix":"# before\nlogprobs = 10\nlogprob_token_ids = [1, 2, 3]\n\n# after\nlogprobs = 3\nlogprob_token_ids = [1, 2, 3]","handlingStrategy":"validation","validationCode":"if let (Some(lp), Some(ids)) = (request.logprobs, request.logprob_token_ids.as_deref()) {\n    assert!(lp == ids.len() as i32,\n        \"logprobs ({lp}) must equal len(logprob_token_ids) ({})\", ids.len());\n}","typeGuard":"fn is_token_ids_mismatch(e: &Error) -> bool {\n    matches!(e, Error::Logprobs(LogprobsError::TokenIdsMismatch { .. }))\n}","tryCatchPattern":"match err {\n    Error::Logprobs(LogprobsError::TokenIdsMismatch { logprobs, num_token_ids }) =>\n        bad_request(format!(\"set logprobs={num_token_ids} or drop it (got {logprobs})\")),\n    _ => /* ... */\n}","preventionTips":["Derive logprobs from the list length in one place: request.logprobs = Some(ids.len() as i32)","Never hand-edit the two fields independently"],"tags":["rust","validation","logprobs","vllm"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}