Bug: coerce_property skips falsy values (0, False, empty string)
Author: feiiiiii5Created Jul 25, 2026Updated Sep 24, 2026
LabelsStale
Description
coerce_property() in guardrails/utils/parsing_utils.py uses truthiness checks (if payload_value:) to determine whether to recurse into property values. This causes legitimate falsy values — 0, 0.0, False, and "" — to be silently skipped during type coercion.
Location
guardrails/utils/parsing_utils.py, lines 364 and 380.
Reproduction
from guardrails.utils.parsing_utils import coerce_types
schema = {
'type': 'object',
'properties': {
'count': {'type': 'string'},
}
}
# Expected: {'count': '0'} (integer 0 coerced to string)
# Actual: {'count': 0} (skipped because bool(0) is False)
result = coerce_types({'count': 0}, schema)
print(result) # {'count': 0} — BUGRoot Cause
payload_value = payload.get(k)
if payload_value: # ← skips 0, False, '', 0.0, []
payload[k] = coerce_property(payload_value, v)Fix
Replace if payload_value: with if payload_value is not None: in both the properties loop (line 364) and the additionalProperties loop (line 380).
Impact
Any LLM-generated JSON payload containing 0, false, or "" values will bypass type coercion, potentially causing downstream validation failures or type mismatches.
Source: guardrails-ai/guardrails