ai-gateway / utils /validation.py
basyx's picture
Upload 58 files
36333c5 verified
Raw
History Blame Contribute Delete
680 Bytes
"""Cross-field input validation."""
from core.errors import GatewayError
def validate_image_dimensions(width: int, height: int, *, multiple: int = 8) -> None:
"""Require dimensions compatible with diffusion VAEs."""
if width % multiple or height % multiple:
raise GatewayError(
f"Image width and height must be multiples of {multiple}",
code="invalid_dimensions",
)
def validate_nonblank(value: str, field_name: str) -> str:
"""Reject strings containing only whitespace."""
cleaned = value.strip()
if not cleaned:
raise GatewayError(f"{field_name} cannot be blank", code="invalid_input")
return cleaned