{"record":{"id":"333d218bad5ee1d3","repo":"mudler/LocalAI","slug":"raw-r-is-not-a-boolean","errorCode":null,"errorMessage":"{raw!r} is not a boolean","messagePattern":"(.+?) is not a boolean","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/python/common/vllm_utils.py","lineNumber":108,"sourceCode":"\n\ndef _type_hint(annotation, current):\n    \"\"\"Best-effort target type name for a dataclass field.\"\"\"\n    hint = _hint_from_annotation(annotation)\n    if hint is None:\n        hint = _hint_from_value(current)\n    return hint\n\n\ndef _coerce_option(raw, hint):\n    \"\"\"Coerce a CLI-supplied string to the field's type. Raises ValueError.\"\"\"\n    if hint == \"bool\":\n        low = raw.lower()\n        if low in _TRUTHY:\n            return True\n        if low in _FALSY:\n            return False\n        raise ValueError(f\"{raw!r} is not a boolean\")\n    if hint == \"int\":\n        return int(raw)\n    if hint == \"float\":\n        return float(raw)\n    if hint == \"dict\":\n        return json.loads(raw)\n    if hint == \"str\":\n        return raw\n\n    # Untyped (or union-typed) field: infer from the literal itself.\n    low = raw.lower()\n    if low in _TRUTHY:\n        return True\n    if low in _FALSY:\n        return False\n    for cast in (int, float):\n        try:\n            return cast(raw)","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/python/common/vllm_utils.py#L90-L126","documentation":"Raised by _coerce_option in the vLLM backend's shared utils when a CLI-supplied string must be coerced to a boolean field but its lowercased value is in neither the truthy nor falsy sets. It guards engine_args validation: any bool-typed ServerArgs field given an unrecognized literal reaches this branch.","triggerScenarios":"Passing a string like 'yes', 'on', 'enabled', '1.0', or 'true ' (with whitespace/typo) via backend options/CLI flags for a field whose type hint resolves to bool, where _TRUTHY/_FALSY only cover the canonical literals (true/false, 1/0, etc. depending on the sets defined in the module).","commonSituations":"Users writing 'yes'/'no' or 'on'/'off' in YAML/JSON backend config, shell-quoting mistakes that append whitespace, or copy-pasting flags from vLLM docs that use different boolean spellings than LocalAI's accepted set.","solutions":["Use canonical boolean literals: true/false (case-insensitive) or whatever _TRUTHY/_FALSY in vllm_utils define — check those sets for the exact accepted spellings.","Strip whitespace and remove surrounding quotes in the config value.","If the value comes from a user-supplied config, normalize it upstream (e.g. 'yes'→'true') before passing engine args.","Check whether the intended field is actually bool-typed in the installed vLLM ServerArgs; a version change may have altered the type hint and hence the coercion path."],"exampleFix":"# before\noptions = {\"enforce_eager\": \"yes\"}\n\n# after\noptions = {\"enforce_eager\": \"true\"}","handlingStrategy":"validation","validationCode":"_BOOL_LITERALS = {\"true\", \"false\", \"1\", \"0\", \"yes\", \"no\"}  # align with _TRUTHY/_FALSY\ndef is_coercible_bool(raw: str) -> bool:\n    return raw.strip().lower() in _BOOL_LITERALS","typeGuard":"def is_valid_engine_option(raw: str, hint: str) -> bool:\n    if hint == \"bool\":\n        return raw.strip().lower() in _TRUTHY | _FALSY\n    try:\n        {\"int\": int, \"float\": float, \"dict\": lambda s: json.loads(s)}.get(hint, lambda s: s)(raw)\n        return True\n    except (ValueError, json.JSONDecodeError):\n        return False","tryCatchPattern":"try:\n    value = _coerce_option(raw_value, \"bool\")\nexcept ValueError:\n    value = raw_value.strip().lower() in (\"true\", \"1\")\n    logger.warning(\"non-canonical boolean %r coerced to %s\", raw_value, value)","preventionTips":["Normalize boolean config values to true/false at the config layer.","Strip whitespace and quotes when ingesting user-supplied engine args.","Validate the whole engine-args dict once at startup, not per request."],"tags":["vllm","configuration","type-coercion","validation"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}