Skip to content

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
@runtime_checkable
class ClaimExtractor(Protocol):
    """Protocol for claim extraction strategies.

    Implementations extract factual claims from document text.
    Different implementations handle different document types and domains.
    """

    async def extract(
        self,
        document: str,
        source_path: str,
        *,
        max_claims: int | None = None,
    ) -> list[Claim]:
        """Extract claims from document text.

        Args:
            document: The document text to analyze.
            source_path: Path or URL of the source document.
            max_claims: Optional limit on number of claims to extract.

        Returns:
            List of extracted Claim objects.
        """
        ...

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
async def extract(
    self,
    document: str,
    source_path: str,
    *,
    max_claims: int | None = None,
) -> list[Claim]:
    """Extract claims from document text.

    Args:
        document: The document text to analyze.
        source_path: Path or URL of the source document.
        max_claims: Optional limit on number of claims to extract.

    Returns:
        List of extracted Claim objects.
    """
    ...

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
@runtime_checkable
class EvidenceGatherer(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.).
    """

    async def gather(
        self,
        claim: Claim,
        context: dict[str, Any],
    ) -> list[Evidence]:
        """Gather evidence for a claim.

        Args:
            claim: The claim to find evidence for.
            context: Workflow context (root_path, config, etc.).

        Returns:
            List of Evidence objects found.
        """
        ...

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
async def gather(
    self,
    claim: Claim,
    context: dict[str, Any],
) -> list[Evidence]:
    """Gather evidence for a claim.

    Args:
        claim: The claim to find evidence for.
        context: Workflow context (root_path, config, etc.).

    Returns:
        List of Evidence objects found.
    """
    ...

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
@runtime_checkable
class ClaimVerifier(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).
    """

    async def verify(
        self,
        claim: Claim,
        evidence: list[Evidence],
    ) -> VerificationResult:
        """Verify a claim against gathered evidence.

        Args:
            claim: The claim to verify.
            evidence: Evidence gathered for this claim.

        Returns:
            VerificationResult with verdict, confidence, and explanation.
        """
        ...

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
async def verify(
    self,
    claim: Claim,
    evidence: list[Evidence],
) -> VerificationResult:
    """Verify a claim against gathered evidence.

    Args:
        claim: The claim to verify.
        evidence: Evidence gathered for this claim.

    Returns:
        VerificationResult with verdict, confidence, and explanation.
    """
    ...

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
@runtime_checkable
class ReportFormatter(Protocol):
    """Protocol for report formatting strategies.

    Implementations produce output in different formats
    (JSON, Markdown, HTML, custom domain-specific formats).
    """

    def format(self, report: TruthfulnessReport) -> str:
        """Format a truthfulness report.

        Args:
            report: The report to format.

        Returns:
            Formatted report as a string.
        """
        ...

    def file_extension(self) -> str:
        """Return the default file extension for this format.

        Returns:
            Extension string (e.g., ".json", ".md", ".html").
        """
        ...

file_extension()

Return the default file extension for this format.

Returns:

Type Description
str

Extension string (e.g., ".json", ".md", ".html").

Source code in src/truthfulness_evaluator/core/protocols.py
def file_extension(self) -> str:
    """Return the default file extension for this format.

    Returns:
        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.

Source code in src/truthfulness_evaluator/core/protocols.py
def format(self, report: TruthfulnessReport) -> str:
    """Format a truthfulness report.

    Args:
        report: The report to format.

    Returns:
        Formatted report as a string.
    """
    ...

Usage Note: Built-in formatters support JSON, Markdown, and HTML output. Implement this protocol to add custom report formats.