Python Exceptions Hierarchy¶
All exceptions raised by typesafe-eval derive from TypeSafeEvalError.
Hierarchy¶
TypeSafeEvalError (Base exception)
├── ConfigurationError (Invalid preset syntax, missing files, config schema errors)
├── AuthenticationError (Missing or invalid TYPESAFE_API_KEY)
├── RuntimeEvalError (Network timeouts, API rate limits, external service failures)
└── ContentViolationError (Raised if strict mode requires raising on gate violations)
Exception Reference¶
TypeSafeEvalError¶
Base exception class for all errors generated by typesafe-eval.
ConfigurationError¶
Raised when: - An invalid preset name or non-existent YAML path is passed. - Preset YAML has invalid syntax or fails Pydantic schema validation. - An input document file path does not exist.
AuthenticationError¶
Raised when:
- TYPESAFE_API_KEY is not found in the environment and not provided via argument (when running in online evaluation mode).
- The TypeSafe API rejects credentials with HTTP 401/403.
RuntimeEvalError¶
Raised when: - Network requests time out or fail to establish a connection. - The remote TypeSafe System One API returns HTTP 5xx or unparseable payloads.
ContentViolationError¶
Raised when explicit gating checks fail in programmatic contexts where an exception is desired rather than inspecting result.passed_thresholds.
Example Usage¶
from typesafe_eval import evaluate_document, AuthenticationError, ConfigurationError
try:
result = evaluate_document("docs/auth.md", preset="safety")
except AuthenticationError:
print("Please set TYPESAFE_API_KEY before running evaluations.")
except ConfigurationError as e:
print(f"Configuration error: {e}")