can1357/oh-my-pi · error · ValueError
{field} must be a boolean
Error message
{field} must be a boolean What it means
`_require_bool` validates that a required payload field is a JSON true/false. It raises ValueError when the field is missing or holds any non-boolean value. This guarantees parsed result objects have genuine booleans rather than truthy ints or strings.
Source
Thrown at python/omp-rpc/src/omp_rpc/protocol.py:213
def _optional_literal(
value: object, allowed: frozenset[str], *, field: str
) -> str | None:
if value is None:
return None
return _require_literal(value, allowed, field=field)
def _require_str(payload: JsonObject, field: str) -> str:
value = payload.get(field)
if not isinstance(value, str):
raise ValueError(f"{field} must be a string")
return value
def _require_bool(payload: JsonObject, field: str) -> bool:
value = payload.get(field)
if not isinstance(value, bool):
raise ValueError(f"{field} must be a boolean")
return value
def _optional_str(payload: JsonObject, field: str) -> str | None:
value = payload.get(field)
if value is None:
return None
if not isinstance(value, str):
raise ValueError(f"{field} must be a string")
return value
def _optional_str_list(payload: JsonObject, field: str) -> tuple[str, ...]:
"""Parse an optional string-or-array-of-strings field.
The agent's `systemPrompt` (and similar) became `string[]` server-side
when multi-prompt support landed. Older daemons still emit a bare string,
so we accept either shape. Returns an empty tuple when the field isView on GitHub (pinned to 9690622007)
Solutions
- Inspect the payload field and convert it to a real bool (bool(int(value)) for 0/1, value == "true" for strings)
- Fix the producer so it emits JSON true/false
- If the field can legitimately be absent, normalize the payload or skip parse_fast_mode_result for it
Example fix
# before
result = parse_fast_mode_result({"enabled": "true"}) # ValueError: enabled must be a boolean
# after
raw = {"enabled": "true"}
result = parse_fast_mode_result({"enabled": raw["enabled"] == "true"}) Defensive patterns
Strategy: validation
Validate before calling
def ensure_bool(payload: dict, field: str) -> None:
if not isinstance(payload.get(field), bool):
raise TypeError(f"{field!r} must be a boolean, got {payload.get(field)!r}")
ensure_bool(payload, "enabled")
parse_fast_mode_result(payload) Type guard
def is_bool_field(payload: dict, field: str) -> bool:
return isinstance(payload.get(field), bool) Try / catch
try:
result = parse_fast_mode_result(payload)
except ValueError as e:
logger.error("fast mode result rejected", extra={"payload": payload, "error": str(e)})
result = None # fall back to non-fast path Prevention
- Emit strict JSON booleans from servers (not 0/1 or "true")
- Add a schema-validation step before parsing RPC responses
- Watch for Python gotchas: bool is a subclass of int, so check bool first
- Version-check the wire protocol on connect
When it happens
Trigger: parse_fast_mode_result receives a payload where the required boolean field is absent, or is 0/1, "true"/"false" (strings), or null.
Common situations: A server serializes booleans as 0/1 (common in DB-backed responses); a mock fixture uses "true" as a string; a schema change made the field optional on the wire but the parser still requires it.
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
- {field} must be a string
- {field}[{index}] must be a string
- {field} must be a string or an array of strings
- {field} must be an integer
- {field} must be a number
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/bd3ff5c7a74bd301.
Report an issue: GitHub.