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.5.tar.gz (7.1 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.5-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for factverifai-0.1.5.tar.gz
Algorithm Hash digest
SHA256 4aa9a31ede28fd88c31114d552a7e6a63df2a4e39fed2ca7acae983a154d8b68
MD5 9949803091848d41f46c1d66a433dd80
BLAKE2b-256 d6eba934efe7aab1f4a51b6c73a705989df9ca763e6edf6ae73972c14b372217

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for factverifai-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b7fe86c7c4913690f09967af2dfbd5a7ebb0064c713123eecf2633933066ff98
MD5 f726d7890767cc583a520626a9dd3a8a
BLAKE2b-256 4f040fdd22a4d0efc83ac722ca0dfc019f44771124ee36f0024478df3d69ad32

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