Protocols
The protocol layer defines the core abstractions for the truthfulness evaluation pipeline. Each protocol represents a distinct responsibility in the workflow:
- ClaimExtractor: Extracts factual claims from input documents
- EvidenceGatherer: Gathers supporting or refuting evidence for claims
- ClaimVerifier: Verifies claims against collected evidence
- ReportFormatter: Formats verification results into human-readable reports
These protocols enable pluggable strategies, allowing you to mix and match different implementations for each stage of the pipeline.
ClaimExtractor
truthfulness_evaluator.core.protocols.ClaimExtractor
Bases: Protocol
Protocol for claim extraction strategies.
Implementations extract factual claims from document text. Different implementations handle different document types and domains.
Source code in src/truthfulness_evaluator/core/protocols.py
extract(document, source_path, *, max_claims=None)
async
Extract claims from document text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document |
str
|
The document text to analyze. |
required |
source_path |
str
|
Path or URL of the source document. |
required |
max_claims |
int | None
|
Optional limit on number of claims to extract. |
None
|
Returns:
| Type | Description |
|---|---|
list[Claim]
|
List of extracted Claim objects. |
Source code in src/truthfulness_evaluator/core/protocols.py
Usage Note: Concrete implementations include SimpleExtractor (general-purpose) and TripletExtractor (subject-predicate-object triples).
EvidenceGatherer
truthfulness_evaluator.core.protocols.EvidenceGatherer
Bases: Protocol
Protocol for evidence gathering strategies.
Implementations search for evidence that supports or refutes claims. Different implementations search different sources (web, filesystem, API endpoints, git history, etc.).
Source code in src/truthfulness_evaluator/core/protocols.py
gather(claim, context)
async
Gather evidence for a claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
claim |
Claim
|
The claim to find evidence for. |
required |
context |
dict[str, Any]
|
Workflow context (root_path, config, etc.). |
required |
Returns:
| Type | Description |
|---|---|
list[Evidence]
|
List of Evidence objects found. |
Source code in src/truthfulness_evaluator/core/protocols.py
Usage Note: Implementations range from WebSearchGatherer (web-based evidence) to FilesystemGatherer (local file evidence) to CompositeGatherer (combines multiple gatherers).
ClaimVerifier
truthfulness_evaluator.core.protocols.ClaimVerifier
Bases: Protocol
Protocol for claim verification strategies.
Implementations judge whether evidence supports, refutes, or is insufficient for a claim. Different implementations use different judgment methods (single LLM, consensus, deterministic).
Source code in src/truthfulness_evaluator/core/protocols.py
verify(claim, evidence)
async
Verify a claim against gathered evidence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
claim |
Claim
|
The claim to verify. |
required |
evidence |
list[Evidence]
|
Evidence gathered for this claim. |
required |
Returns:
| Type | Description |
|---|---|
VerificationResult
|
VerificationResult with verdict, confidence, and explanation. |
Source code in src/truthfulness_evaluator/core/protocols.py
Usage Note: Choose between SingleModelVerifier (fast, single LLM), ConsensusVerifier (multi-model voting), or InternalVerifier (code-documentation alignment).
ReportFormatter
truthfulness_evaluator.core.protocols.ReportFormatter
Bases: Protocol
Protocol for report formatting strategies.
Implementations produce output in different formats (JSON, Markdown, HTML, custom domain-specific formats).
Source code in src/truthfulness_evaluator/core/protocols.py
file_extension()
Return the default file extension for this format.
Returns:
| Type | Description |
|---|---|
str
|
Extension string (e.g., ".json", ".md", ".html"). |
format(report)
Format a truthfulness report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report |
TruthfulnessReport
|
The report to format. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted report as a string. |
Usage Note: Built-in formatters support JSON, Markdown, and HTML output. Implement this protocol to add custom report formats.