from typing import Optional class ValidationError(Exception): """Custom exception for JSON schema validation errors.""" def __init__(self, path: str, message: str): """Initialize validation error. Args: path: JSON path to the failing field message: Human-readable error message """ self.path = path self.message = message super().__init__(f"Validation error at {path}: {message}") def __str__(self) -> str: """Return formatted error message.""" return f"Error at {self.path}: {self.message}" def __repr__(self) -> str: """Return detailed representation.""" return f"ValidationError(path='{self.path}', message='{self.message}')" def to_dict(self) -> dict: """Convert error to dictionary representation. Returns: Dictionary with path and message keys """ return { "path": self.path, "message": self.message }