Skip to main content

Validate LLM responses with composable, production-ready checks

Project description

chaincheck-llm

Validate LLM responses with composable, production-ready checks.

pip install chaincheck-llm

The Problem

LLMs return unpredictable output. Sometimes they leak PII. Sometimes they refuse to answer. Sometimes they hallucinate. You need a way to validate responses before they reach your users.

chaincheck-llm gives you a composable validation pipeline — run any combination of checks on any LLM response.

Quick Start

from chaincheck import validate
from chaincheck.checks import (
    check_not_empty,
    check_no_pii,
    check_no_toxicity,
    check_min_length,
)

result = validate(
    response=llm_output,
    checks=[
        check_not_empty,
        check_no_pii,
        check_no_toxicity,
        lambda r: check_min_length(r, min_chars=50),
    ]
)

print(result.passed)    # True / False
print(result.score)     # 0.0 - 1.0
print(result.summary())

Available Checks

Format Checks (free, no LLM needed)

Check Description
check_not_empty Response is not empty
check_min_length(r, min_chars) Response meets minimum length
check_max_length(r, max_chars) Response within maximum length
check_json_valid Response is valid JSON
check_contains(r, keywords) Response contains required keywords
check_not_contains(r, forbidden) Response has no forbidden words
check_regex(r, pattern) Response matches regex pattern
check_no_placeholder No unfilled {variable} placeholders

Content Checks (free, rule-based)

Check Description
check_no_pii No email, phone, SSN, credit card
check_no_toxicity No toxic/harmful language
check_no_hallucination_markers No uncertainty disclaimers
check_no_refusal LLM did not refuse to answer
check_language(r, expected) Response is in expected language

LLM-as-Judge Checks (uses tokens)

Check Description
check_relevance(r, question, ...) Response is relevant to question
check_factual_consistency(r, context, ...) Response consistent with context
check_tone(r, expected_tone, ...) Response matches expected tone

Composing Checks

from chaincheck import validate
from chaincheck.checks import (
    check_not_empty, check_no_pii, check_no_toxicity,
    check_relevance, check_min_length,
)

result = validate(
    response=llm_output,
    checks=[
        # Fast rule-based checks first
        check_not_empty,
        check_no_pii,
        check_no_toxicity,
        lambda r: check_min_length(r, min_chars=100),
        # LLM judge last (costs tokens)
        lambda r: check_relevance(
            r,
            question="What is machine learning?",
            provider="openai",
            model="gpt-4o-mini",
            api_key="sk-...",
        ),
    ],
    fail_fast=True,  # stop after first failure
)

if not result.passed:
    for check in result.failed_checks:
        print(f"FAILED: {check.name}{check.message}")

ValidationResult

result.passed           # True if all checks passed
result.score            # Average score (0.0 - 1.0)
result.checks           # List of CheckResult
result.passed_checks    # Checks that passed
result.failed_checks    # Checks that failed
result.summary()        # Dict with full breakdown

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chaincheck_llm-0.1.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chaincheck_llm-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file chaincheck_llm-0.1.0.tar.gz.

File metadata

  • Download URL: chaincheck_llm-0.1.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for chaincheck_llm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f5076ac1e3ff6703a9654849fb944827a2acf7e5e5a4daa79d282812f34d9d79
MD5 37c4197b01626daffd189ed69da5e000
BLAKE2b-256 cb1ed3592153b815c60e6e2fa612b157d39a3691a8cbcc2bac614722b11ce68e

See more details on using hashes here.

File details

Details for the file chaincheck_llm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: chaincheck_llm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for chaincheck_llm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 913b14b8799c3bdb5567b12bc1d9634bafd04560e4d7d287933d0dc0d0af1c98
MD5 886c90dd0846f7ae309deb648f6efcc4
BLAKE2b-256 82a85110127ad5aad39cdada7ffc16154239effa77805674baf9af9b46526c1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page