Witnesses
These validation contracts are distinct from tool results. The SDK supplies types and helpers; it does not execute validators or enforce a gate.
A WitnessRule supplies validate(content: str, **kwargs) -> WitnessResult.
Unlike ToolResult, the result uses the boolean field passed.
Its optional verdict is routing information for a consumer, not a validated
enumeration or a scheduler action.
from axm import ValidationFeedback, WitnessResult
feedback = ValidationFeedback(
what="Title missing",
why="The document requires a title",
how="Add a level-one heading",
)
result = WitnessResult.failure(feedback, verdict="repair")
assert not result.passed
assert feedback.to_dict()["how"] == "Add a level-one heading"
accepted = WitnessResult.success(verdict="continue", metadata={"checked": 1})
assert accepted.passed
All three feedback strings (what, why, how) are required.
to_dict() returns those same three keys.
The helpers success and failure populate a result; they do not execute
a validator or constrain the caller's choice of verdict.
ValidationFeedback
dataclass
Structured feedback for validation failures.
Attributes:
| Name | Type | Description |
|---|---|---|
what |
str
|
What failed (brief description) |
why |
str
|
Why it failed (expected vs actual) |
how |
str
|
How to fix it (actionable guidance) |
Source code in packages/axm/src/axm/witnesses.py
WitnessResult
dataclass
Result of a witness validation.
Attributes:
| Name | Type | Description |
|---|---|---|
passed |
bool
|
Whether validation passed |
feedback |
ValidationFeedback | None
|
Feedback if validation failed |
verdict |
str | None
|
Optional routing decision for Gates |
metadata |
dict[str, Any]
|
Optional execution metadata |
Source code in packages/axm/src/axm/witnesses.py
failure(feedback, verdict=None, metadata=None)
classmethod
Create a failing result with feedback.
Source code in packages/axm/src/axm/witnesses.py
| Python | |
|---|---|
success(verdict=None, metadata=None)
classmethod
Create a passing result.
WitnessRule
Bases: Protocol
Protocol for witness validation rules.
Source code in packages/axm/src/axm/witnesses.py
validate(content, **kwargs)
Validate content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
The content to validate |
required |
**kwargs
|
Any
|
Additional validation parameters |
{}
|
Returns:
| Type | Description |
|---|---|
WitnessResult
|
WitnessResult indicating pass/fail with feedback |