{"record":{"id":"26d0ddb5a594bcf4","repo":"sgl-project/sglang","slug":"invalid-field-name-value-r","errorCode":null,"errorMessage":"Invalid {field_name}={value!r}.","messagePattern":"Invalid (.+?)=(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/speculative/dflash_utils.py","lineNumber":519,"sourceCode":"\n    sample_from_anchor = dflash_config.get(\n        \"sample_from_anchor\", _cfg_get(config, \"sample_from_anchor\", True)\n    )\n    return sample_from_anchor is False\n\n\ndef _parse_optional_int(\n    value: Any,\n    *,\n    field_name: str,\n    min_value: Optional[int] = None,\n) -> Optional[int]:\n    if value is None:\n        return None\n    try:\n        parsed = int(value)\n    except Exception as e:\n        raise ValueError(f\"Invalid {field_name}={value!r}.\") from e\n    if min_value is not None and parsed < int(min_value):\n        comparator = \"positive\" if int(min_value) == 1 else f\">= {int(min_value)}\"\n        raise ValueError(f\"{field_name} must be {comparator}, got {parsed}.\")\n    return parsed\n\n\n@dataclass(frozen=True)\nclass DFlashDraftConfig:\n    num_hidden_layers: Optional[int]\n    num_target_layers: Optional[int]\n    block_size: Optional[int]\n    conv_kernel_size: int\n    conv_group_size: int\n    selector_rank: int\n    selector_top_k: int\n    output_multiplier: float\n    final_logit_softcapping: Optional[float]\n    target_layer_ids: Optional[List[int]]","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/speculative/dflash_utils.py#L501-L537","documentation":"Raised by _parse_optional_int while parsing the DFLASH draft config: the field's value is not None and cannot be converted with int(). This is a config deserialization error — a required-numeric field was given a non-numeric value such as a bad string or a nested object.","triggerScenarios":"parse_dflash_draft_config on a config where a field like speculative_num_draft_tokens is \"eight\", \"\", [8], or a dict; any int(field) call raising ValueError/TypeError.","commonSituations":"Hand-edited draft config JSON with quoted or malformed numbers; YAML/JSON passing a list where a scalar int is expected; env-var overrides injected as strings like \"null\" instead of null.","solutions":["Fix the offending field in the draft config to be an integer or null.","Use the error's chained cause (raise ... from e) and the field_name in the message to identify which field failed, then correct just that entry.","Validate the draft config JSON with a schema/lint before deploying."],"exampleFix":"# before\n{\"speculative_num_draft_tokens\": \"eight\"}\n# after\n{\"speculative_num_draft_tokens\": 8}","handlingStrategy":"validation","validationCode":"for k, v in draft_cfg.items():\n    if v is not None and not isinstance(v, (int, float)):\n        try:\n            int(v)\n        except (TypeError, ValueError):\n            raise ValueError(f'{k} must be int-convertible, got {v!r}')","typeGuard":"def is_int_like(v) -> bool:\n    if v is None or isinstance(v, bool):\n        return v is None\n    try:\n        int(v)\n        return True\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    cfg = parse_dflash_draft_config(raw)\nexcept ValueError as e:\n    raise ConfigError(f'draft config invalid: {e}') from e","preventionTips":["Validate the draft config JSON against a schema before deployment.","Never hand-type numeric config values as strings."],"tags":["speculative-decoding","dflash","config-parsing","type-validation"],"backgroundTag":"config-parse-error","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}