{"record":{"id":"f6c936c90d1040a8","repo":"larksuite/cli","slug":"expected-boolean","errorCode":null,"errorMessage":"expected boolean","messagePattern":"expected boolean","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/lark-slides/scripts/sxsd_validator.py","lineNumber":489,"sourceCode":"        \"code\": code,\n        \"path\": path,\n        \"tag\": tag,\n        \"expected\": expected,\n        \"actual\": actual,\n        \"message\": message,\n        \"hint\": hint,\n    }\n    if attr is not None:\n        result[\"attr\"] = attr\n    return result\n\n\ndef builtin_scalar_value(type_name: str, value: str) -> Decimal | str | bool:\n    if type_name in {\"string\", \"anyURI\"}:\n        return value\n    if type_name == \"boolean\":\n        if value not in {\"true\", \"false\", \"1\", \"0\"}:\n            raise ValueError(\"expected boolean\")\n        return value in {\"true\", \"1\"}\n    if type_name in {\"integer\", \"positiveInteger\", \"nonNegativeInteger\"}:\n        if re.fullmatch(r\"[+-]?\\d+\", value) is None:\n            raise ValueError(\"expected integer\")\n        number = Decimal(value)\n        if type_name == \"positiveInteger\" and number <= 0:\n            raise ArithmeticError(\"expected positive integer\")\n        if type_name == \"nonNegativeInteger\" and number < 0:\n            raise ArithmeticError(\"expected non-negative integer\")\n        return number\n    if type_name in {\"double\", \"decimal\"}:\n        lexical_value = value.strip(\" \\t\\n\\r\")\n        decimal_pattern = r\"[+-]?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)\"\n        double_pattern = decimal_pattern + r\"(?:[eE][+-]?[0-9]+)?\"\n        expected_pattern = double_pattern if type_name == \"double\" else decimal_pattern\n        if re.fullmatch(expected_pattern, lexical_value) is None:\n            raise ValueError(f\"expected {type_name}\")\n        try:","sourceCodeStart":471,"sourceCodeEnd":507,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/skills/lark-slides/scripts/sxsd_validator.py#L471-L507","documentation":"builtin_scalar_value converts a lexical string into the Python value for a built-in XML Schema type. For xs:boolean it accepts only 'true', 'false', '1', '0' (the full XSD lexical space); anything else raises ValueError('expected boolean') so schema validation reports the node's value as type-invalid rather than silently coercing it.","triggerScenarios":"Validating a document where an element/attribute of schema type boolean has a lexical value outside {true, false, 1, 0} — e.g. 'yes', 'no', 'TRUE', 'on', 'True', or an empty string — via scalar_value_for_type/value_error_for_type in the sxsd validator.","commonSituations":"Documents generated by code that serializes booleans as 'True'/'False' (Python str(bool)) or 'yes'/'no' (config-style); hand-edited XML; locale-specific literals; templates with unfilled placeholders like '{{enabled}}'.","solutions":["Fix the source value to one of the XSD-legal literals: true, false, 1, or 0 (case-sensitive, all lowercase).","Fix the serializer: use str(value).lower() or ('true' if value else 'false') when writing boolean fields, not str(value).","Pre-validate the string in the caller before invoking the validator (see validationCode) to produce a clearer message.","If the field should not be boolean, correct the schema (or the type name passed to the validator) to string and re-run."],"exampleFix":"// before\nxml = f\"<flag>{str(enabled)}</flag>\"   # writes 'True' -> ValueError: expected boolean\n\n// after\nxml = f\"<flag>{'true' if enabled else 'false'}</flag>\"","handlingStrategy":"validation","validationCode":"def is_xsd_boolean(value: str) -> bool:\n    return value in {\"true\", \"false\", \"1\", \"0\"}\n\nif not is_xsd_boolean(raw):\n    raise SystemExit(f\"{raw!r} is not an XSD boolean literal (use true/false/1/0)\")","typeGuard":"def is_xsd_boolean(value: str) -> bool:\n    return value in {\"true\", \"false\", \"1\", \"0\"}","tryCatchPattern":"try:\n    parsed = builtin_scalar_value(\"boolean\", raw)\nexcept ValueError as err:\n    if str(err) == \"expected boolean\":\n        raw = {\"yes\": \"true\", \"no\": \"false\"}.get(raw.strip().lower(), raw)\n        if not is_xsd_boolean(raw):\n            raise SystemExit(f\"invalid boolean literal: {raw!r}\") from None\n        parsed = builtin_scalar_value(\"boolean\", raw)\n    else:\n        raise","preventionTips":["Serialize booleans as lowercase 'true'/'false', never str(True) or 'yes'/'no'.","Remember XSD boolean literals are case-sensitive; 'TRUE' is invalid.","Run the schema validator in CI so bad literals surface before consumers do.","Use templates with explicit typed placeholders instead of free-text substitution."],"tags":["xsd","validation","schema","boolean"],"backgroundTag":"schema-validation-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}