Skip to main content

AI-powered fact-checking Python library

Project description

FactVerfAI

Is a Python package that enables robust, automated fact-checking of claims and statements using the latest open-source LLMs and web search APIs. Given any text, FactVerifAI intelligently extracts one or more fact-checkable claims, queries the web for evidence, and generates a json output fact-checking report with references. The package supports parallel processing for faster performance. It is ideal for journalists, researchers, developers, and anyone who wants to automate claim verification in a reproducible, auditable way. It supports local hosted LLMs via Ollama and Open AI backends.


To install the package:

pip install factverifai

How to use

  • Create new .env example from .env.example and paste EXA api key
  • (Optional) add Open AI api key here.

How to use with Open AI

import os
from dotenv import load_dotenv
from factverifai import fact_check

load_dotenv()

text = "British cuisine is the best in the world."

result = fact_check(
    text,
    model="albert-small",
    llm_backend="openai",
    max_workers=4,
    verbose=True,
    exa=os.getenv('EXA_API_KEY'),
    openai_api_key=os.getenv('ALBERT_API_KEY'),
    openai_base_url="https://albert.api.etalab.gouv.fr/v1"
)

How to use with Ollama (local LLM)

import os
from dotenv import load_dotenv
from factverifai import fact_check

load_dotenv()

text = "Nicușor Dan is the president of Romania in 2025, winning against Simion"

result = fact_check(
    text,
    model="llama3.1",
    llm_backend="ollama",
    max_workers=4,
    verbose=True,
    exa=os.getenv('EXA_API_KEY'),
)

max_workers sets parallelism (higher is faster for many claims).

verbose=True enables detailed debug printing.

Setup for developers

  1. Create and install the environment and dependencies. This will:

Go to the folder where factverifai is and run the Makefile:

make

This will:

  • Create a virtual environment named factverifai-env (if it doesn't already exist)
  • Install pip-tools if necessary
  • Compile and install both main and development dependencies
  • Add a Jupyter kernel for the virtual environment (if not already added)
  1. Activate the environment:
source factverifai-env/bin/activate
  1. Configure Ollama or OPEN AI

Visit the Ollama website https://ollama.com/download and download the latest version.

Install the version used in this project

ollama pull llama3.1

Or register for an OPEN AI api key.

  1. Register for an Exa Api Key

Register on the Exa website and generate an API key.

  1. Configure Secrets Make a copy of the .env.example file and save it as .envinside the factverify folder. Add the EXA_API_KEY and your Open AI api key (if required) to your .env file.

Note: If a new key or variable is added to the .env file, make sure to update the .env.example file as well. This ensures others know what environment variables are needed without exposing actual secrets.

Managing dependencies

In this project, main dependencies are those required for the core functionality of the project and are necessary for both development and production environments. These should be added to requirements.in. On the other hand, development dependencies are only needed during development (e.g., testing tools, linters, and debuggers). These should be added to requirements-dev.in. By keeping them separate, we ensure that production environments remain lean and only contain essential packages, while development environments have everything needed for effective development and testing.

To manage and install dependencies, you can use the provided Makefile. It offers the following targets:

  • make — Installs both main and development dependencies.

  • make requirements — Installs main dependencies from requirements.in.

  • make dev-requirements — Installs development dependencies from requirements-dev.in.

  • For main dependencies (needed for both development and production):

    • If you want to add a library to the main installation, add the package name to requirements.in.
    • Run make requirements to install them.
  • For development dependencies (only needed during development):

    • If you are exploring libraries and want to add them for development purposes, add the library to requirements-dev.in.
    • Run make dev-requirements to install them.
  • To install all dependencies (both main and development):

    • Run make to install everything.

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

factverifai-0.1.8.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

factverifai-0.1.8-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file factverifai-0.1.8.tar.gz.

File metadata

  • Download URL: factverifai-0.1.8.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for factverifai-0.1.8.tar.gz
Algorithm Hash digest
SHA256 0cbb38106d843b6e911a25d2dcf7cce52a9fca7310eee6ac75e18045c7713478
MD5 67272211f6fb5ec5b86551adfd2e5298
BLAKE2b-256 67b4fb36d81d7591af2fc9cb98e433fb2249fd63422bda3c9d6e4276b0c942a5

See more details on using hashes here.

File details

Details for the file factverifai-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: factverifai-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for factverifai-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ecd390b07b5eaac37ae0475610806e51e4acd76b38e56a28619f7e1791e287a6
MD5 48b63acf3d0262c1b8cfa67b746614fc
BLAKE2b-256 0a5dfb28b622572445318ddbaa09eeece8e00e5ee66ab85fe5c1940f63dbe256

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