langchain - ✅(Solved) Fix Add RunnableFactChecker for post-generation verification in RAG pipelines [1 pull requests, 4 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36481Fetched 2026-04-08 02:33:22
View on GitHub
Comments
4
Participants
4
Timeline
13
Reactions
0
Author
Timeline (top)
commented ×4labeled ×3closed ×1cross-referenced ×1

Fix Action

Fixed

PR fix notes

PR #36480: feat(core): add RunnableFactChecker for post-generation verification

Description (problem / solution / changelog)

Closes #36481

Summary

Adds RunnableFactChecker to verify LLM outputs against context in RAG pipelines.

Features

  • Sentence-level verification using LLM
  • Confidence score computation
  • Optional strict mode to filter unsupported statements
  • Async support via ainvoke
  • Lazy import integration to avoid circular dependencies

Example

fact_checker = RunnableFactChecker(llm=verifier_llm, strict_mode=True)

result = fact_checker.invoke({
    "context": docs,
    "answer": generated_text
})


---

## 🔹 3. Check Files (VERY IMPORTANT)

Make sure ONLY these are in PR:

```text
✅ fact_checker.py
✅ test_fact_checker.py
✅ __init__.py (lazy import)

## Changed files

- `libs/core/langchain_core/runnables/__init__.py` (modified, +5/-1)
- `libs/core/langchain_core/runnables/fact_checker.py` (added, +61/-0)
- `libs/core/tests/unit_tests/runnables/test_fact_checker.py` (added, +52/-0)
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a feature request, not a bug report or usage question.
  • I added a clear and descriptive title that summarizes the feature request.
  • I used the GitHub search to find a similar feature request and didn't find it.
  • I checked the LangChain documentation and API reference to see if this feature already exists.
  • This is not related to the langchain-community package.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Feature Description

Feature Request

Introduce a RunnableFactChecker to verify LLM outputs against provided context in RAG pipelines.

Motivation

LLMs can generate hallucinated or unsupported information, especially in retrieval-augmented generation (RAG) workflows. A fact-checking step can improve reliability by validating generated outputs.

Proposed Solution

  • Sentence-level verification using an LLM
  • Confidence score computation based on supported statements
  • Optional strict mode to filter unsupported sentences
  • Runnable-compatible for LCEL pipelines

Example

fact_checker = RunnableFactChecker(llm=verifier_llm, strict_mode=True)

result = fact_checker.invoke({
    "context": docs,
    "answer": generated_text
})

### Use Case

I'm trying to build a Retrieval-Augmented Generation (RAG) application where LLM responses are generated based on retrieved documents.

Currently, there is no built-in mechanism in LangChain to verify whether the generated response is actually grounded in the provided context. This often leads to hallucinated or unsupported statements, especially in multi-step pipelines.

Right now, I have to manually implement post-processing logic to:
- split responses into sentences
- verify each statement using an additional LLM call
- compute a confidence score
- optionally filter unsupported content

This feature would help users by providing a reusable and composable `Runnable` that:
- verifies LLM outputs against context
- integrates directly into LCEL pipelines
- provides confidence scoring
- optionally enforces strict grounding (filtering unsupported statements)

This would be especially useful for:
- RAG pipelines
- QA systems
- enterprise applications requiring higher reliability

It would reduce repeated boilerplate and provide a standardized approach to post-generation verification.

### Proposed Solution

_No response_

### Alternatives Considered

_No response_

### Additional Context

_No response_

extent analysis

TL;DR

Implement a RunnableFactChecker to verify LLM outputs against provided context in RAG pipelines.

Guidance

  • Review the proposed solution for the RunnableFactChecker and consider its integration into LCEL pipelines.
  • Evaluate the benefits of sentence-level verification, confidence score computation, and optional strict mode for filtering unsupported sentences.
  • Assess the potential impact on RAG pipelines, QA systems, and enterprise applications requiring higher reliability.
  • Consider the trade-offs between accuracy, computational overhead, and implementation complexity.

Example

# Example usage of the proposed RunnableFactChecker
fact_checker = RunnableFactChecker(llm=verifier_llm, strict_mode=True)
result = fact_checker.invoke({
    "context": docs,
    "answer": generated_text
})

Notes

The implementation details of the RunnableFactChecker are not provided, and its development may require additional consideration of factors like performance, scalability, and compatibility with existing LangChain components.

Recommendation

Apply workaround: Implement a custom fact-checking mechanism using existing LangChain components and LLMs, until the proposed RunnableFactChecker is available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING