{"record":{"id":"6ca6d8f2bfa19f97","repo":"HumanSignal/label-studio","slug":"incorrect-bool-value-value-it-should-be-one-o","errorCode":null,"errorMessage":"Incorrect bool value \"{value}\". It should be one of [1, 0, true, false, yes, no]","messagePattern":"Incorrect bool value \"(.+?)\"\\. It should be one of \\[1, 0, true, false, yes, no\\]","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"label_studio/core/utils/params.py","lineNumber":14,"sourceCode":"import os\nfrom typing import Callable, Optional, Sequence, TypeVar\n\nfrom rest_framework.exceptions import ValidationError\n\n\ndef cast_bool_from_str(value):\n    if isinstance(value, str):\n        if value.lower() in ['true', 'yes', 'on', '1']:\n            value = True\n        elif value.lower() in ['false', 'no', 'not', 'off', '0']:\n            value = False\n        else:\n            raise ValueError(f'Incorrect bool value \"{value}\". It should be one of [1, 0, true, false, yes, no]')\n    return value\n\n\ndef bool_from_request(params, key, default):\n    \"\"\"Get boolean value from request GET, POST, etc\n\n    :param params: dict POST, GET, etc\n    :param key: key to find\n    :param default: default value\n    :return: boolean\n    \"\"\"\n    value = params.get(key, default)\n\n    try:\n        if isinstance(value, str):\n            value = cast_bool_from_str(value)\n        return bool(int(value))\n    except Exception as e:","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/core/utils/params.py#L1-L32","documentation":"cast_bool_from_str converts request string values to booleans, accepting only a fixed set of truthy ('true','yes','on','1') and falsy ('false','no','not','off','0') words (case-insensitive). Any other string raises ValueError with the allowed values listed. Non-string values pass through unchanged.","triggerScenarios":"Passing a query/body parameter parsed by bool_from_request or filters (cast_value, add_result_filter, add_user_filter, annotation_id_filter_q, normalize_persisted_user_filter) whose value is a string other than the accepted words — e.g. 'True ' is fine (lowered) but 'enabled', 't', '2', or 'oui' raise.","commonSituations":"Frontends sending 'enabled'/'disabled' or localized booleans; users typing filters in the URL like ?aggregation=true-ish; API consumers sending 'Y'/'N'; accidentally sending a word where a boolean is expected.","solutions":["Send one of the accepted values: 1, 0, true, false, yes, no (case-insensitive; 'on'/'off'/'not' also accepted).","Sanitize/normalize the value on the client before sending, mapping your app's boolean vocabulary to these words.","If parsing untrusted input, wrap the call in try/except ValueError and fall back to a default.","Inspect the request param that carries this value — the message includes the offending string."],"exampleFix":"// before\nGET /api/projects/?was_enabled=yes&include=maybe\n// after — only accepted words for boolean params\nGET /api/projects/?was_enabled=yes&include=true","handlingStrategy":"validation","validationCode":"ACCEPTED = {'true','yes','on','1','false','no','not','off','0'}\ndef is_bool_str(v) -> bool:\n    return not isinstance(v, str) or v.lower() in ACCEPTED","typeGuard":"def parse_bool(value):\n    if isinstance(value, str):\n        if value.lower() in ('true','yes','on','1'): return True\n        if value.lower() in ('false','no','not','off','0'): return False\n        return None  # invalid\n    return bool(value)","tryCatchPattern":"try:\n    flag = bool_from_request(params, 'include', False)\nexcept ValueError as e:\n    return Response({'error': str(e)}, status=400)","preventionTips":["Normalize booleans on the client to true/false before sending.","Document accepted boolean words in your API docs.","Never send localized or synonym booleans ('Y','enabled').","Default the parameter when absent rather than sending junk values."],"tags":["validation","parameters","boolean","request"],"backgroundTag":"invalid-boolean-value","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}