Labsco
AdamGustavsson logo

Claimify

β˜… 14

from AdamGustavsson

Extracts factual claims from text using the Claimify methodology. Requires an OpenAI API key.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredAdvanced setup

Claimify: Research-Based Claim Extraction via MCP

An implementation of the "Claimify" methodology for factual claim extraction, delivered as a local Model Context Protocol (MCP) server. This tool implements the multi-stage claim extraction approach detailed in the academic paper "Towards Effective Extraction and Evaluation of Factual Claims" by Metropolitansky & Larson (2025).

Read the paper here

Promps from the paper have been modified for use with Structured Outputs. THIS IS NOT AN OFFICIAL IMPLEMENTATION.

Overview

Claimify extracts verifiable, decontextualized factual claims from text using a sophisticated four-stage pipeline:

  1. Sentence Splitting: Breaks text into individual sentences with surrounding context
  2. Selection: Filters for sentences containing verifiable propositions, excluding opinions and speculation
  3. Disambiguation: Resolves ambiguities or discards sentences that cannot be clarified
  4. Decomposition: Breaks down sentences into atomic, self-contained factual claims

The tool uses OpenAI's structured outputs feature exclusively for improved reliability and exposes its functionality through the Model Context Protocol, making it available to MCP-compatible clients like Cursor and Claude Desktop.

Features

  • Research-based methodology: Implements the peer-reviewed Claimify approach
  • Structured outputs: Uses OpenAI's structured outputs for reliable, type-safe responses
  • MCP integration: Seamlessly integrates with development environments
  • Robust parsing: Handles various text formats including lists and paragraphs
  • Context-aware: Uses surrounding sentences to resolve ambiguities
  • Multi-language support: Preserves original language while extracting claims
  • Resource storage: Automatically stores extracted claims as MCP resources for easy retrieval
  • Comprehensive logging: Detailed logging of all LLM calls, responses, and pipeline stages
  • Production-ready: Includes error handling, monitoring, and configuration management

Claims

Claim 1

Text: Apple Inc. was founded in 1976.

Status: TODO


Claim 2

Text: Steve Jobs co-founded Apple Inc.

Status: TODO


...


**After verification updates:**
```markdown
### Claim 1
**Text:** Apple Inc. was founded in 1976.

**Status:** VERIFIED

**Evidence:**
- Source 1: [Wikipedia - Apple Inc.](https://en.wikipedia.org/wiki/Apple_Inc.) - States company was founded in 1976
- Source 2: [Apple Official](https://www.apple.com/about/) - Corporate history confirms 1976 founding
- Source 3: [Britannica](https://www.britannica.com/topic/Apple-Inc) - Encyclopedia entry validates founding year

---

### Claim 2
**Text:** Stockholm has 800,000 inhabitants.

**Status:** UNCERTAIN

**Evidence:**
- Source 1: [Statistics Sweden](https://www.scb.se/en/) - Reports varying figures depending on definition

**Analysis:**
The claim lacks specificity about which geographic definition and time period. Population varies significantly between city proper (~975k), municipality (~975k), and metropolitan area (~1.6M) as of 2023. The 800k figure may have been accurate historically for certain definitions.

---

### Claim 3
**Text:** The company invented smartphones.

**Status:** DISPUTED

**Analysis:**
While Apple popularized smartphones with the iPhone in 2007, they did not invent smartphones. Earlier devices like the IBM Simon (1994) and BlackBerry devices (early 2000s) preceded the iPhone. The claim conflates innovation/popularization with invention.

---
...

Note: The server only supplies the prompts; external searching depends on the client/model capabilities.

Example 1: Simple Factual Text

Input: "The American flag contains 50 stars and 13 stripes."
Output: [
  "The American flag contains 50 stars [representing the 50 states] and 13 stripes [representing the original 13 colonies].",
  "The American flag was designed in 1777",
  "The American flag has been modified 27 times"
]

Example 2: Mixed Fact and Opinion

Input: "Apple Inc. was founded in 1976 by Steve Jobs, Steve Wozniak, and Ronald Wayne. The company is incredibly innovative and has the best products in the world."
Output: [
  "Apple Inc. was founded in 1976 by Steve Jobs, Steve Wozniak, and Ronald Wayne."
]

(Note: The subjective content about being "incredibly innovative" and having "the best products" is filtered out)

Example 3: Multi-language Support

Input: "String-systemet Γ€r en prisbelΓΆnt ikon som kombinerar elegant och minimalistisk design med ett brett utbud av fΓ€rger och storlekar. Nisse Strinning skapade fΓΆrsta hyllan redan 1949."
Output: [
  "String-systemet [ett hyllsystem] Γ€r en prisbelΓΆnt ikon [inom design]",
  "String-systemet kombinerar elegant och minimalistisk design med ett brett utbud av fΓ€rger och storlekar",
  "Nisse Strinning skapade den fΓΆrsta String-hyllan [String-systemet] 1949"
]

(Note: Content preserved in original Swedish, with contextual clarifications added in brackets)

Accessing Extracted Claims as Resources

Each extraction generates two kinds of resources:

  1. Aggregate Extraction Resource (claim://extraction_<n>_<timestamp>)
    • Contains metadata (timestamp, preview, question) and the full list of claims
    • Returns JSON format
  2. Individual Claim Resources (claim://<slug>)
    • Each claim is accessible via a unique slug (URL-safe identifier derived from claim text)
    • Returns plain text (the claim itself)

Aggregate Extraction JSON Example

{
  "id": "extraction_1_1730678400",
  "timestamp": "2025-11-03T14:30:00.123456",
  "question": "What is the history of Apple?",
  "text_preview": "Apple Inc. was founded in 1976 by Steve Jobs...",
  "claims": [
    "Apple Inc. was founded in 1976 by Steve Jobs, Steve Wozniak, and Ronald Wayne."
  ],
  "claim_count": 1
}

URI: claim://apple-inc-was-founded-in-1976-by-steve-jobs

Individual Claim Resource Examples

URI pattern: claim://<slug>

Examples:

  • claim://apple-inc-was-founded-in-1976-by-steve-jobs-steve-wozniak-and-ronald
  • claim://stockholm-is-the-capital-of-sweden
  • claim://python-was-first-publicly-released-in-1991

Content: Plain text of the claim (no JSON wrapper)

Benefits of per-claim resources:

  • Direct access: Retrieve any claim by its slug
  • Simple format: Plain text, no parsing needed
  • Unique identifiers: Each claim has a stable, readable URI
  • Easy citation: Link directly to individual claims

Project Structure

ClaimsMCP/
β”œβ”€β”€ README.md                    # This file
β”œβ”€β”€ requirements.txt             # Python dependencies
β”œβ”€β”€ env.example                  # Environment configuration template
β”œβ”€β”€ claimify_server.py          # Main MCP server script
β”œβ”€β”€ llm_client.py               # LLM client with structured outputs support
β”œβ”€β”€ pipeline.py                 # Core claim extraction pipeline
β”œβ”€β”€ structured_models.py        # Pydantic models for structured outputs
β”œβ”€β”€ structured_prompts.py       # Optimized prompts for structured outputs
β”œβ”€β”€ setup.py                    # Package setup configuration
β”œβ”€β”€ test_claimify.py            # Test suite for the claim extraction pipeline
└── LICENSE                     # Apache 2.0 license

Architecture

The system follows a modular architecture with structured outputs:

  • MCP Server: Exposes the claim extraction as a tool via the Model Context Protocol
  • ClaimifyPipeline: Orchestrates the multi-stage extraction process using structured outputs
  • LLMClient: Handles communication with OpenAI API using structured outputs and Pydantic models
  • Structured Models: Pydantic models that define the expected response format for each stage
  • Stage Functions: Individual functions for Selection, Disambiguation, and Decomposition
  • Prompt Management: Simplified prompts optimized for structured outputs

Structured Outputs Benefits

The implementation uses OpenAI's structured outputs feature, which provides:

  • Type Safety: Responses are automatically validated against Pydantic models
  • Reliability: No more regex parsing failures or malformed JSON
  • Explicit Refusals: Safety-based refusals are programmatically detectable
  • Consistency: Guaranteed adherence to the expected response schema
  • Performance: Reduced need for retry logic and error handling

Development

To extend or modify the system:

  1. Adding new response fields: Update the Pydantic models in structured_models.py
  2. Modifying prompts: Edit the prompts in structured_prompts.py
  3. Adding new stages: Create new functions in pipeline.py following the existing pattern
  4. Testing: Use the built-in logging to debug pipeline behavior

The structured outputs approach makes the system much more reliable and easier to debug compared to traditional text parsing methods.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

References

Metropolitansky & Larson (2025). "Towards Effective Extraction and Evaluation of Factual Claims"

Support

For issues related to:

  • Setup and configuration: Check this README and the troubleshooting section
  • MCP integration: Refer to the Model Context Protocol documentation
  • Research methodology: Consult the original Claimify paper