{"record":{"id":"e58034494c4a01f5","repo":"sgl-project/sglang","slug":"min-new-tokens-must-be-in-0-max-new-tokens-self","errorCode":null,"errorMessage":"min_new_tokens must be in [0, max_new_tokens({self.max_new_tokens})], got {self.min_new_tokens}.","messagePattern":"min_new_tokens must be in \\[0, max_new_tokens\\((.+?)\\)\\], got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/sampling/sampling_params.py","lineNumber":201,"sourceCode":"        if not 0 <= self.min_new_tokens:\n            raise ValueError(\n                f\"min_new_tokens must be in [0, max_new_tokens], got \"\n                f\"{self.min_new_tokens}.\"\n            )\n        if self.max_new_tokens is not None:\n            if self.max_new_tokens < 0:\n                raise ValueError(\n                    f\"max_new_tokens must be at least 0, got {self.max_new_tokens}.\"\n                )\n            if not self.min_new_tokens <= self.max_new_tokens:\n                raise ValueError(\n                    f\"min_new_tokens must be in [0, max_new_tokens({self.max_new_tokens})], got \"\n                    f\"{self.min_new_tokens}.\"\n                )\n        if self.logit_bias is not None:\n            for token_id in self.logit_bias:\n                if not 0 <= int(token_id) < vocab_size:\n                    raise ValueError(\n                        f\"logit_bias must has keys in [0, {vocab_size - 1}], got \"\n                        f\"{token_id}.\"\n                    )\n\n        grammars = [\n            self.json_schema,\n            self.regex,\n            self.ebnf,\n            self.structural_tag,\n        ]  # since mutually exclusive, only one can be set\n        if sum(x is not None for x in grammars) > 1:\n            raise ValueError(\n                \"Only one of json_schema, regex, ebnf, or structural_tag can be set.\"\n            )\n\n    def normalize(self, tokenizer):\n        # Process stop strings\n        if self.stop_strs is None:","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/sampling/sampling_params.py#L183-L219","documentation":"verify() enforces the invariant 0 <= min_new_tokens <= max_new_tokens when max_new_tokens is set. A min greater than max makes the generation window empty/contradictory, so the request is rejected up front during normalize().","triggerScenarios":"Setting SamplingParams(min_new_tokens=50, max_new_tokens=20), or raising min_new_tokens for 'don't emit short answers' while a low max_new_tokens is set globally (e.g. server default or per-request override).","commonSituations":"Copied min_new_tokens from one config into a request with a smaller max_new_tokens; global default max_new_tokens on the server clashing with per-request min; tuning min_p/min_new_tokens for constrained-grammar decoding.","solutions":["Raise max_new_tokens to at least min_new_tokens.","Lower min_new_tokens (or drop it to 0)."],"exampleFix":"# before\nSamplingParams(min_new_tokens=100, max_new_tokens=50)\n# after\nSamplingParams(min_new_tokens=50, max_new_tokens=100)","handlingStrategy":"validation","validationCode":"max_new_tokens = max_new_tokens if max_new_tokens is not None else float('inf')\nassert 0 <= min_new_tokens <= max_new_tokens, (min_new_tokens, max_new_tokens)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set min/max token counts together in one config object.","When overriding max_new_tokens per request, re-check the global min_new_tokens default."],"tags":["sampling-params","validation","min-new-tokens","sglang"],"backgroundTag":"invalid-parameter-validation","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}