Validation¶
Classes and functions for validating OAS specifications and workflow structures.
OASSchemaValidator¶
Validates OAS input dictionaries before conversion.
OASSchemaValidator
¶
Validates OAS (Open Agent Spec) dictionaries before conversion.
Performs validation to ensure the input data has the correct structure before attempting to convert it to Dapr formats.
Usage
validator = OASSchemaValidator() result = validator.validate_agent(agent_dict) if not result.is_valid: for error in result.errors: print(error)
Or with strict mode:¶
validator.validate_agent(agent_dict, raise_on_error=True)
Functions¶
validate_component
¶
Validate any OAS component based on its type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
The component dictionary to validate |
required |
raise_on_error
|
bool
|
If True, raise OASSchemaValidationError on errors |
False
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with all issues found |
Raises:
| Type | Description |
|---|---|
OASSchemaValidationError
|
If raise_on_error=True and validation fails |
Source code in src/dapr_agents_oas_adapter/validation.py
validate_agent
¶
Validate an Agent component dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
The agent dictionary to validate |
required |
raise_on_error
|
bool
|
If True, raise OASSchemaValidationError on errors |
False
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with all issues found |
Raises:
| Type | Description |
|---|---|
OASSchemaValidationError
|
If raise_on_error=True and validation fails |
Source code in src/dapr_agents_oas_adapter/validation.py
validate_flow
¶
Validate a Flow component dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
The flow dictionary to validate |
required |
raise_on_error
|
bool
|
If True, raise OASSchemaValidationError on errors |
False
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with all issues found |
Raises:
| Type | Description |
|---|---|
OASSchemaValidationError
|
If raise_on_error=True and validation fails |
Source code in src/dapr_agents_oas_adapter/validation.py
StrictLoader¶
Loader wrapper that validates OAS specs before conversion.
StrictLoader
¶
A validating wrapper around DaprAgentSpecLoader.
This loader validates OAS specifications against schema rules before attempting conversion, providing early error detection and better error messages.
Example
from dapr_agents_oas_adapter import StrictLoader
# Create a strict loader
loader = StrictLoader()
# This will validate the dict before loading
config = loader.load_dict(spec_dict)
# Invalid specs will raise OASSchemaValidationError
try:
config = loader.load_dict(invalid_dict)
except OASSchemaValidationError as e:
for issue in e.issues:
print(issue)
Initialize the strict loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_registry
|
ToolRegistry | None
|
Dictionary mapping tool names to their callable implementations. |
None
|
warn_on_unknown_fields
|
bool
|
If True, unknown fields trigger warnings |
True
|
Source code in src/dapr_agents_oas_adapter/loader.py
Attributes¶
Functions¶
register_tool
¶
Register a tool implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The tool name as defined in the OAS specification |
required |
implementation
|
Callable[..., Any]
|
The callable implementation |
required |
Source code in src/dapr_agents_oas_adapter/loader.py
load_dict
¶
load_dict(
spec_dict: dict[str, Any], *, validate: bool = True
) -> DaprAgentConfig | WorkflowDefinition
Load an OAS specification from a dictionary with validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec_dict
|
dict[str, Any]
|
Dictionary containing the OAS specification |
required |
validate
|
bool
|
Whether to validate before loading (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
DaprAgentConfig | WorkflowDefinition
|
DaprAgentConfig for Agent components, WorkflowDefinition for Flows |
Raises:
| Type | Description |
|---|---|
OASSchemaValidationError
|
If validation fails |
ConversionError
|
If the component type is not supported |
Source code in src/dapr_agents_oas_adapter/loader.py
validate_dict
¶
Validate a dictionary without loading it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec_dict
|
dict[str, Any]
|
Dictionary containing the OAS specification |
required |
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with all issues found |
Source code in src/dapr_agents_oas_adapter/loader.py
load_json
¶
Load an OAS specification from JSON string with optional validation.
Note: Full validation is only available for load_dict. This method parses JSON then delegates to load_dict for validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_content
|
str
|
JSON string containing the OAS specification |
required |
validate
|
bool
|
Whether to validate before loading (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
DaprAgentConfig | WorkflowDefinition
|
DaprAgentConfig for Agent components, WorkflowDefinition for Flows |
Raises:
| Type | Description |
|---|---|
OASSchemaValidationError
|
If validation fails |
ConversionError
|
If the JSON cannot be parsed or converted |
Source code in src/dapr_agents_oas_adapter/loader.py
load_yaml
¶
Load an OAS specification from YAML string with optional validation.
Note: Full validation is only available for load_dict. This method parses YAML then delegates to load_dict for validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml_content
|
str
|
YAML string containing the OAS specification |
required |
validate
|
bool
|
Whether to validate before loading (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
DaprAgentConfig | WorkflowDefinition
|
DaprAgentConfig for Agent components, WorkflowDefinition for Flows |
Raises:
| Type | Description |
|---|---|
OASSchemaValidationError
|
If validation fails |
ConversionError
|
If the YAML cannot be parsed or converted |
Source code in src/dapr_agents_oas_adapter/loader.py
create_agent
¶
create_agent(
config: DaprAgentConfig,
additional_tools: dict[str, Callable[..., Any]]
| None = None,
) -> Any
Create an executable Dapr Agent from configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DaprAgentConfig
|
The agent configuration |
required |
additional_tools
|
dict[str, Callable[..., Any]] | None
|
Additional tool implementations to include |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A Dapr Agent instance (AssistantAgent or ReActAgent) |
Raises:
| Type | Description |
|---|---|
ConversionError
|
If agent creation fails |
Source code in src/dapr_agents_oas_adapter/loader.py
create_workflow
¶
create_workflow(
workflow_def: WorkflowDefinition,
task_implementations: dict[str, Callable[..., Any]]
| None = None,
) -> NamedCallable
Create an executable Dapr workflow from definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_def
|
WorkflowDefinition
|
The workflow definition |
required |
task_implementations
|
dict[str, Callable[..., Any]] | None
|
Task implementations for workflow activities |
None
|
Returns:
| Type | Description |
|---|---|
NamedCallable
|
A workflow function that can be registered with Dapr |
Raises:
| Type | Description |
|---|---|
ConversionError
|
If workflow creation fails |
Source code in src/dapr_agents_oas_adapter/loader.py
WorkflowValidator¶
Validates workflow structure after conversion.
WorkflowValidator
¶
Comprehensive validator for WorkflowDefinition objects.
Performs three levels of validation: 1. Structure validation: Required fields, proper types 2. Reference validation: Node references exist, no orphans 3. Edge validation: Connected graph, no cycles in control flow, branching consistency
Usage
validator = WorkflowValidator() result = validator.validate(workflow_def) if not result.is_valid: for error in result.errors: print(error)
Or raise on first error:¶
result.raise_if_invalid()
Functions¶
validate
¶
Validate a workflow definition comprehensively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
WorkflowDefinition
|
The workflow definition to validate |
required |
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with all issues found |
Source code in src/dapr_agents_oas_adapter/validation.py
ValidationResult¶
Result object returned by validators.
ValidationResult
dataclass
¶
Result of a validation operation.
Attributes¶
Functions¶
add_error
¶
add_error(
message: str,
field: str | None = None,
suggestion: str | None = None,
cause: Exception | None = None,
) -> None
Add an error-level issue.
Source code in src/dapr_agents_oas_adapter/validation.py
add_warning
¶
Add a warning-level issue.
Source code in src/dapr_agents_oas_adapter/validation.py
merge
¶
raise_if_invalid
¶
Raise WorkflowValidationError if there are any errors.
If the first error has a cause, it is chained via raise ... from.
Source code in src/dapr_agents_oas_adapter/validation.py
validate_oas_dict¶
Convenience function for OAS validation.
validate_oas_dict
¶
Convenience function to validate an OAS component dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
The OAS component dictionary to validate |
required |
raise_on_error
|
bool
|
If True, raise OASSchemaValidationError on errors |
False
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with all issues found |
Raises:
| Type | Description |
|---|---|
OASSchemaValidationError
|
If raise_on_error=True and validation fails |
Source code in src/dapr_agents_oas_adapter/validation.py
validate_workflow¶
Convenience function for workflow validation.
validate_workflow
¶
validate_workflow(
workflow: WorkflowDefinition,
*,
raise_on_error: bool = False,
) -> ValidationResult
Convenience function to validate a workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
WorkflowDefinition
|
The workflow definition to validate |
required |
raise_on_error
|
bool
|
If True, raise WorkflowValidationError on validation errors |
False
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with all issues found |
Raises:
| Type | Description |
|---|---|
WorkflowValidationError
|
If raise_on_error=True and validation fails |
Source code in src/dapr_agents_oas_adapter/validation.py
Exceptions¶
OASSchemaValidationError¶
OASSchemaValidationError
¶
OASSchemaValidationError(
issues: list[ValidationIssue] | None = None,
message: str = "",
field_path: str | None = None,
)
Bases: ValidationError
Exception raised when OAS schema validation fails.
Initialize with list of validation issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issues
|
list[ValidationIssue] | None
|
List of validation issues found during validation |
None
|
message
|
str
|
Optional error message (used by parent constructor) |
''
|
field_path
|
str | None
|
Optional field path (used by parent constructor) |
None
|
Source code in src/dapr_agents_oas_adapter/validation.py
Functions¶
WorkflowValidationError¶
WorkflowValidationError
¶
WorkflowValidationError(
issues: list[ValidationIssue] | None = None,
message: str = "",
field_path: str | None = None,
)
Bases: ValidationError
Exception raised when workflow validation fails.
Initialize with list of validation issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issues
|
list[ValidationIssue] | None
|
List of validation issues found during validation |
None
|
message
|
str
|
Optional error message (used by parent constructor) |
''
|
field_path
|
str | None
|
Optional field path (used by parent constructor) |
None
|
Source code in src/dapr_agents_oas_adapter/validation.py
Functions¶
Usage Examples¶
OAS Validation¶
from dapr_agents_oas_adapter import (
StrictLoader,
OASSchemaValidator,
validate_oas_dict
)
from dapr_agents_oas_adapter.validation import OASSchemaValidationError
# Using StrictLoader
loader = StrictLoader()
try:
config = loader.load_dict(spec)
except OASSchemaValidationError as e:
print(f"Errors: {e.issues}")
# Using validator directly
validator = OASSchemaValidator()
result = validator.validate(spec)
if not result.is_valid:
for error in result.errors:
print(error)
# Using convenience function
result = validate_oas_dict(spec)
Workflow Validation¶
from dapr_agents_oas_adapter import (
WorkflowValidator,
validate_workflow
)
from dapr_agents_oas_adapter.validation import WorkflowValidationError
# Using validator
validator = WorkflowValidator()
result = validator.validate(workflow)
# Using convenience function
result = validate_workflow(workflow)
# Raise on error
try:
validate_workflow(workflow, raise_on_error=True)
except WorkflowValidationError as e:
print(f"Validation failed: {e}")