Skip to main content

cot-coherence

Detect silent incoherence in AI chain-of-thought reasoning.

Most evaluation tools check if each reasoning step is correct. cot-coherence checks if the logical progression between steps holds together — schema-level coherence, not step-level accuracy.

Why?

Chain-of-thought reasoning in LLMs silently degrades. Recent research (arXiv, Feb-Mar 2026) shows:

  • CoT faithfulness decays at 70-85% of chain length ("Reasoning Horizon")
  • Reasoning tokens have a negative effect past this horizon
  • No existing tool detects this — current tools check RAG grounding, linguistic flow, or safety. None check logical coherence between steps.

cot-coherence fills this gap.

Install

pip install cot-coherence

With CLI support:

pip install cot-coherence[cli]

With LLM-powered detection:

pip install cot-coherence[llm]

Quick Start

import cot_coherence

report = cot_coherence.analyze("""
Step 1: The user asks about Python performance.
Step 2: Python is interpreted, so it's generally slower than compiled languages.
Step 3: Let me discuss the history of JavaScript frameworks.
Step 4: Therefore, Python is definitely the fastest language available.
""", original_question="Is Python fast?")

print(report.overall_score)  # 0.43
print(report.is_coherent)    # False
print(len(report.flags))     # 3+ (scope_creep, conclusion_drift, confidence_inflation)

What It Detects

5 Incoherence Patterns

Pattern What It Catches Example
Premise Abandonment Premises introduced but never referenced again "Given PostgreSQL uses RLS..." then never mentions DB security
Conclusion Drift Conclusions that shift topic mid-chain Concludes about databases, then about Kubernetes
Confidence Inflation Unjustified jumps from hedging to certainty "might work" → "definitely always works" with no evidence
Scope Creep Reasoning that drifts from the original question Asked about Python, starts discussing Roman architecture
Circular Return Steps that repeat earlier reasoning Step 5 restates Step 1 in different words

Reasoning Horizon

Detects the point in a chain where quality starts to degrade — the "Reasoning Horizon" described in recent research. Reports the estimated horizon position and degradation signals.

CLI

# Analyze a trace file
cot-coherence check trace.txt -q "What is quantum computing?"

# Pipe from stdin
echo "Step 1: ..." | cot-coherence check

# JSON output
cot-coherence check trace.txt --json-output

# Adjust sensitivity (0.0=lenient, 1.0=strict)
cot-coherence check trace.txt -s 0.8

# Disable horizon analysis
cot-coherence check trace.txt --no-horizon

LLM Mode (v0.2+)

Rule-based detection is free and works offline. For higher accuracy, enable LLM-powered detection using Claude Haiku as a second-pass verifier:

export ANTHROPIC_API_KEY=your-key-here

# CLI
cot-coherence check trace.txt -q "your question" --use-llm

# Python
from cot_coherence import analyze, CoherenceConfig

config = CoherenceConfig(use_llm=True)
report = analyze(trace_text, original_question="...", config=config)

The LLM:

  • Validates rule-based flags (reduces false positives)
  • Discovers issues the rules missed (reduces false negatives)
  • Enriches flag summaries with better explanations

Cost: ~$0.001 per trace (single API call). If the API fails, rule-based results are returned automatically.

Configuration

from cot_coherence import analyze, CoherenceConfig, IncoherenceType

config = CoherenceConfig(
    sensitivity=0.7,                    # 0.0=lenient, 1.0=strict
    enabled_detectors={                 # Enable specific detectors
        IncoherenceType.PREMISE_ABANDONMENT,
        IncoherenceType.CONFIDENCE_INFLATION,
    },
    analyze_horizon=True,               # Enable horizon analysis
    weights={                           # Custom pattern weights
        IncoherenceType.PREMISE_ABANDONMENT: 2.0,
        IncoherenceType.CONFIDENCE_INFLATION: 1.5,
    },
)

report = analyze("Step 1: ...", config=config)

Trace Formats

Auto-detects 4 formats:

# Numbered (default for most LLMs)
"Step 1: First\nStep 2: Second"
"1. First\n2. Second"

# XML (Claude-style thinking)
"<step>First</step><step>Second</step>"
"<thinking>Reasoning here</thinking>"

# Markdown
"## Step 1\nFirst\n## Step 2\nSecond"

# Newline-separated (fallback)
"First block\n\nSecond block"

Or pass pre-split steps:

report = analyze(steps=["First step", "Second step"])

Custom Parsers

from cot_coherence import register_parser
from cot_coherence.models import ReasoningStep

def my_parser(text):
    parts = text.split("|||")
    return [ReasoningStep(index=i, text=p.strip(), raw_text=p)
            for i, p in enumerate(parts) if p.strip()]

register_parser("pipe", my_parser)
report = analyze("First ||| Second ||| Third", trace_format="pipe")

The CoherenceReport

report = analyze(trace)

report.overall_score    # float 0.0-1.0
report.is_coherent      # True if score >= 0.7
report.steps            # list[ReasoningStep]
report.flags            # list[IncoherenceFlag]
report.critical_flags   # flags with CRITICAL severity
report.horizon          # HorizonAnalysis or None
report.pattern_scores   # dict[IncoherenceType, float]

# Each flag contains:
flag.type               # IncoherenceType enum
flag.severity           # LOW, MEDIUM, HIGH, CRITICAL
flag.confidence         # 0.0-1.0
flag.step_range         # (start_step, end_step)
flag.summary            # Human-readable description
flag.evidence           # Specific evidence
flag.suggestion         # How to fix it

How It Works

v0.1 uses rule-based heuristics — zero API cost, works offline:

  • Premise Abandonment: Extracts premise markers ("given", "assuming"), checks if key entities appear in subsequent steps
  • Conclusion Drift: Identifies conclusion markers ("therefore", "thus"), compares topic overlap via Jaccard similarity
  • Confidence Inflation: Tracks hedging vs. certainty word ratios, flags unjustified jumps without evidence markers
  • Scope Creep: Measures content-word overlap between each step and the original question
  • Circular Return: Computes content-word fingerprints, flags high similarity between non-adjacent steps

Scoring: each pattern starts at 1.0, penalties applied per flag based on severity and confidence. Overall score is the weighted average.

Dependencies

Required: pydantic>=2.0

Optional:

  • [cli]click, rich (for terminal interface)
  • [llm]anthropic (for future LLM-powered detection)
  • [dev]pytest, pytest-cov, ruff, mypy

License

Apache 2.0

Release files for cot-coherence 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cot-coherence 0.2.0
File Size Uploaded
cot_coherence-0.2.0.tar.gz 31.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cot-coherence 0.2.0
File Interpreter ABI Platform
cot_coherence-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 61.8 kB

Release files / cot_coherence-0.2.0.tar.gz

Download URL cot_coherence-0.2.0.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7d78f6370301b22cd670f3003a0f24b55c00a2a73bb9ecddadb0ba0df3e82a84
BLAKE2b-256 checksum
How to use checksums
04245132672c7ae5f41a97179257b10d9471c79a3912673c1b3769c9af81b1a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 27, 2026.

Transparency log

Release files / cot_coherence-0.2.0-py3-none-any.whl

Download URL cot_coherence-0.2.0-py3-none-any.whl
Size 30.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3ed371e3423d8d0902653a67dce4114994c7b05bd72e48c67a47bf0509f4dea
BLAKE2b-256 checksum
How to use checksums
6b7ae428db79457605eace5f7b167fa4cdd5058f98587aca80700df9442c56f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page