validation_utils
Validation and type conversion utilities.
This module provides utilities for type conversion and validation, leveraging, for instance, Pydantic's validation capabilities for consistent type handling across the codebase.
Module
Functions
normalize_boolean
def normalize_boolean(value: Any) ‑> bool:Convert string booleans to actual booleans using Pydantic's logic.
This is defensive programming to handle cases where string representations of booleans (e.g., "false", "False", "true", "True") might be passed instead of actual boolean values. This can happen if template replacement doesn't work correctly, or if values come from a different code path.
Uses Pydantic's TypeAdapter for boolean validation, which handles common string representations like "true"/"false", "yes"/"no", "1"/"0", etc.
NOTE: non-empty, "non-boolean" strings will be converted to True as they are inherently truthy. This means that even "false"-like strings might be converted to True if they are not of a type that Pydantic can validate as a boolean. See Pydantic's documentation for more details.
Arguments
value: Value that should be a boolean (may be bool, str, or other type).
Returns Boolean value. Uses Pydantic's boolean validation which handles strings like "true", "false", "yes", "no", "1", "0", etc. Falls back to bool() conversion if Pydantic can't validate it.