import json import os from pathlib import Path def _schema_path() -> Path: base = Path(__file__).resolve().parents[1] return base / "schemas" / "event.json" def validate_event(event: dict) -> None: if os.environ.get("JAMES_VALIDATE_SCHEMA", "1") != "1": return try: import jsonschema except Exception as exc: # pragma: no cover - runtime guard raise RuntimeError(f"jsonschema is required for validation: {exc}") schema = json.loads(_schema_path().read_text()) jsonschema.validate(instance=event, schema=schema)