larksuite/cli · error · ValueError
expected boolean
Error message
expected boolean
What it means
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.
Source
Thrown at skills/lark-slides/scripts/sxsd_validator.py:489
"code": code,
"path": path,
"tag": tag,
"expected": expected,
"actual": actual,
"message": message,
"hint": hint,
}
if attr is not None:
result["attr"] = attr
return result
def builtin_scalar_value(type_name: str, value: str) -> Decimal | str | bool:
if type_name in {"string", "anyURI"}:
return value
if type_name == "boolean":
if value not in {"true", "false", "1", "0"}:
raise ValueError("expected boolean")
return value in {"true", "1"}
if type_name in {"integer", "positiveInteger", "nonNegativeInteger"}:
if re.fullmatch(r"[+-]?\d+", value) is None:
raise ValueError("expected integer")
number = Decimal(value)
if type_name == "positiveInteger" and number <= 0:
raise ArithmeticError("expected positive integer")
if type_name == "nonNegativeInteger" and number < 0:
raise ArithmeticError("expected non-negative integer")
return number
if type_name in {"double", "decimal"}:
lexical_value = value.strip(" \t\n\r")
decimal_pattern = r"[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)"
double_pattern = decimal_pattern + r"(?:[eE][+-]?[0-9]+)?"
expected_pattern = double_pattern if type_name == "double" else decimal_pattern
if re.fullmatch(expected_pattern, lexical_value) is None:
raise ValueError(f"expected {type_name}")
try:View on GitHub (pinned to 7fd6ef3c07)
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.
Example fix
// before
xml = f"<flag>{str(enabled)}</flag>" # writes 'True' -> ValueError: expected boolean
// after
xml = f"<flag>{'true' if enabled else 'false'}</flag>" Defensive patterns
Strategy: validation
Validate before calling
def is_xsd_boolean(value: str) -> bool:
return value in {"true", "false", "1", "0"}
if not is_xsd_boolean(raw):
raise SystemExit(f"{raw!r} is not an XSD boolean literal (use true/false/1/0)") Type guard
def is_xsd_boolean(value: str) -> bool:
return value in {"true", "false", "1", "0"} Try / catch
try:
parsed = builtin_scalar_value("boolean", raw)
except ValueError as err:
if str(err) == "expected boolean":
raw = {"yes": "true", "no": "false"}.get(raw.strip().lower(), raw)
if not is_xsd_boolean(raw):
raise SystemExit(f"invalid boolean literal: {raw!r}") from None
parsed = builtin_scalar_value("boolean", raw)
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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}}'.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- expected integer
- expected positive integer
- expected non-negative integer
- L1: inputSchema must not be nil
- L1: inputSchema.properties must not be nil
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/f6c936c90d1040a8.
Report an issue: GitHub.