Decorator
@predicate
Convert a comparison function into a full predicate with automatic result wrapping. Signature:| Name | Type | Description |
|---|---|---|
func | Callable | Function that returns bool and accepts actual and reference (as the first two positional args, or as actual=, reference= keywords) |
Predicate - A wrapped callable that returns PredicateResult
Example:
Result Classes
PredicateResult
Result of a predicate evaluation with metadata and confidence. Attributes:| Name | Type | Description |
|---|---|---|
actual | str | String representation of observed value |
reference | str | String representation of expected value |
name | str | Name of the predicate function |
strict | bool | Strictness flag used in evaluation |
confidence | float | Confidence score in [0, 1] |
value | bool | Boolean outcome of the check |
message | str | None | Optional explanation or reasoning |
| Method | Returns | Description |
|---|---|---|
__bool__() | bool | Appends the result to the current collector (if any), then returns value |
__repr__() | str | JSON representation (Pydantic model_dump_json) |
Built-in Semantic Predicates
All built-in predicates are async functions that returnPredicateResult.
has_conflicting_facts
Check if actual text contradicts facts in reference text. Signature:| Name | Type | Default | Description |
|---|---|---|---|
actual | str | - | Text produced by the system under test |
reference | str | - | Source text or context for grounding |
strict | bool | False | Whether to require explicit contradictions |
PredicateResult - value is True if contradictions found
Example:
has_unsupported_facts
Check if actual text contains facts not found in reference text (hallucinations). Signature:| Name | Type | Default | Description |
|---|---|---|---|
actual | str | - | Text produced by the system under test |
reference | str | - | Source text that should ground all facts |
strict | bool | False | Whether to require explicit support |
PredicateResult - value is True if unsupported facts found
Example:
has_facts
Check if actual text contains all facts from reference text. Signature:| Name | Type | Default | Description |
|---|---|---|---|
actual | str | - | Text produced by the system under test |
reference | str | - | Required facts that must be present |
strict | bool | False | Whether to require exact factual match |
PredicateResult - value is True if all required facts present
Example:
matches_facts
Check if actual and reference texts convey the same set of facts (bidirectional). Signature:| Name | Type | Default | Description |
|---|---|---|---|
actual | str | - | Text produced by the system under test |
reference | str | - | Ground truth to compare against |
strict | bool | False | Whether to require strict semantic equality |
PredicateResult - value is True if texts are factually equivalent
Example:
has_topics
Check if actual text covers all topics from reference text. Signature:| Name | Type | Default | Description |
|---|---|---|---|
actual | str | - | Text produced by the system under test |
reference | str | - | Required topics (comma-separated or description) |
strict | bool | False | Whether to require exact topic match |
PredicateResult - value is True if all topics covered
Example:
follows_policy
Check if actual text adheres to rules/policies in reference text. Signature:| Name | Type | Default | Description |
|---|---|---|---|
actual | str | - | Text produced by the system under test |
reference | str | - | Policies, rules, or requirements |
strict | bool | False | Whether to enforce strict adherence |
PredicateResult - value is True if compliant with policy
Example:
matches_writing_style
Check if actual text has the same writing style as reference text. Signature:| Name | Type | Default | Description |
|---|---|---|---|
actual | str | - | Text produced by the system under test |
reference | str | - | Example showing desired style |
strict | bool | False | Whether to require strict stylistic match |
PredicateResult - value is True if style matches
Example:
matches_writing_layout
Check if actual text follows the same structure as reference template. Signature:| Name | Type | Default | Description |
|---|---|---|---|
actual | str | - | Text produced by the system under test |
reference | str | - | Template showing desired structure |
strict | bool | False | Whether to require strict structural match |
PredicateResult - value is True if layout matches
Example: