{"record":{"id":"7ff8e1f18ab2088a","repo":"vllm-project/vllm","slug":"parameter-must-be-non-negative-or-1-got-value","errorCode":null,"errorMessage":"{parameter} must be non-negative or -1, got {value}","messagePattern":"(.+?) must be non-negative or -1, got (.+?)","errorType":"validation","errorClass":"LogprobsError","httpStatus":400,"severity":"error","filePath":"rust/src/text/src/lower/logprobs.rs","lineNumber":15,"sourceCode":"// SPDX-License-Identifier: Apache-2.0\n// SPDX-FileCopyrightText: Copyright contributors to the vLLM project\n\n//! Python-compatible validation for logprobs sampling params.\n//!\n//! `-1` is expanded only for bounds checks. The original request values are\n//! passed through to engine-core.\n\nuse thiserror::Error;\n\nuse crate::backend::SamplingLimits;\n\n#[derive(Debug, Error)]\npub enum LogprobsError {\n    #[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(","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/rust/src/text/src/lower/logprobs.rs#L1-L33","documentation":"Logprobs count validation (rust/src/text/src/lower/logprobs.rs:113) rejects any negative value for `logprobs` / `prompt_logprobs` (and the server's `max_logprobs` limit) other than the `-1` sentinel, which expands to the full vocabulary size for bounds checks. Message: `{parameter} must be non-negative or -1, got {value}`.","triggerScenarios":"Sending `logprobs: -5` or `prompt_logprobs: -2` in a request; configuring the server with a negative `max_logprobs` limit. Only exactly -1 is accepted as 'all tokens'.","commonSituations":"Clients from OpenAI-compat ecosystems sending 0/-1 style flags with other negative numbers; config generation that defaults unset ints to -1 but occasionally emits -2; confusion between 'disabled' (omit the field) and -1 (everything).","solutions":["Use -1 exactly for 'all logprobs', or a non-negative integer for the top-K count","Omit logprobs/prompt_logprobs entirely when you do not want them"],"exampleFix":"// before\nrequest.logprobs = -2;\n\n// after\nrequest.logprobs = -1; // all\n// or\nrequest.logprobs = 20;  // top-20","handlingStrategy":"validation","validationCode":"for (name, v) in [(\"logprobs\", logprobs), (\"prompt_logprobs\", prompt_logprobs)] {\n    if let Some(v) = v {\n        assert!(v == -1 || v >= 0, \"{name} must be non-negative or -1, got {v}\");\n    }\n}","typeGuard":"fn is_invalid_count(e: &Error) -> bool {\n    matches!(e, Error::Logprobs(LogprobsError::InvalidCount { .. }))\n}","tryCatchPattern":"match err {\n    Error::Logprobs(LogprobsError::InvalidCount { parameter, value }) =>\n        bad_request(format!(\"{parameter} must be non-negative or -1, got {value}\")),\n    _ => /* ... */\n}","preventionTips":["Use exactly -1 for 'all', non-negative for top-K; omit otherwise","Centralize logprobs-count handling in one client helper instead of per-call literals"],"tags":["rust","validation","logprobs","vllm"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}