julee.util.validation¶
Validation utilities for type checking and debugging serialization issues.
This module provides utilities for validating runtime types against expected types, with special focus on debugging common serialization issues in Temporal workflows where Pydantic models get deserialized as dictionaries.
Submodules¶
Exceptions¶
Raised when repository contract validation fails |
|
Raised when type validation fails with detailed diagnostics. |
Functions¶
|
Validate and return a repository with proper type annotation. |
|
Simple guard check function for manual validation. |
|
Decorator to validate function parameters against their expected types. |
|
Validate that a repository implementation satisfies a protocol contract. |
|
Validate that a value matches the expected type with detailed diagnostics. |
Package Contents¶
- exception julee.util.validation.RepositoryValidationError[source]¶
Bases:
ExceptionRaised when repository contract validation fails
- exception julee.util.validation.TypeValidationError[source]¶
Bases:
TypeErrorRaised when type validation fails with detailed diagnostics.
- julee.util.validation.ensure_repository_protocol(repository, protocol)[source]¶
Validate and return a repository with proper type annotation.
This provides both runtime validation and static type checking benefits.
- Parameters:
repository (object) – The repository implementation to validate
protocol (type[P]) – The protocol class to validate against
- Returns:
The validated repository (type checker knows it satisfies the protocol)
- Raises:
RepositoryValidationError – If validation fails
- Return type:
Example
>>> from julee.util.validation.repository import ensure_repository_protocol >>> from julee.domain.repositories import DocumentRepository >>> repo = MinioDocumentRepository() >>> validated_repo = ensure_repository_protocol(repo, DocumentRepository) >>> # Type checker now knows validated_repo satisfies DocumentRepository
- julee.util.validation.guard_check(value, expected_type, context_name='value')[source]¶
Simple guard check function for manual validation.
- Usage:
guard_check(queries, Dict[str, KnowledgeServiceQuery], “queries”) guard_check(document, Document, “document”)
- julee.util.validation.validate_parameter_types(**expected_types)[source]¶
Decorator to validate function parameters against their expected types.
- Usage:
@validate_parameter_types(queries=Dict[str, KnowledgeServiceQuery]) def my_function(self, queries):
# parameters are validated before function runs pass
- Or automatically from type hints:
@validate_parameter_types() def my_function(self, queries: Dict[str, KnowledgeServiceQuery]):
# type hints are used automatically pass
- julee.util.validation.validate_repository_protocol(repository, protocol)[source]¶
Validate that a repository implementation satisfies a protocol contract.
Uses Python’s built-in isinstance() with @runtime_checkable for robust, idiomatic protocol validation.
- Parameters:
repository (object) – The repository implementation to validate
protocol (type[P]) – The protocol class to validate against
- Raises:
RepositoryValidationError – If validation fails
Example
>>> from julee.util.validation.repository import validate_repository_protocol >>> from julee.domain.repositories import DocumentRepository >>> repo = MinioDocumentRepository() >>> validate_repository_protocol(repo, DocumentRepository)
- julee.util.validation.validate_type(value, expected_type, context_name='value', allow_none=False)[source]¶
Validate that a value matches the expected type with detailed diagnostics.
- Parameters:
value (Any) – The actual value to validate
expected_type (Any) – The expected type (from type hints)
context_name (str) – Name for error messages (e.g., “parameter ‘queries’”)
allow_none (bool) – Whether None values are acceptable
- Raises:
TypeValidationError – With detailed diagnosis if type doesn’t match