Skip to main content

Algorithmically generated logic games for LLM fine-tuning and misinformation detection.

Project description

LogicJitter

LogicJitter: Let LLMs play and uncover misinformation

Paper License: CC BY 4.0

Python package for automatically generating logic-based training data to improve LLM reasoning and misinformation detection.

Authors: Luca Herranz-Celotti · Marco Viviani
Published in: Computers and Electrical Engineering 136 (2026) 111215

Read the paper: LogicJitter on ScienceDirect
DOI: 10.1016/j.compeleceng.2026.111215


Overview

LogicJitter generates structured, rule-based logic games in natural language. Each sample includes valid and fallacious reasoning patterns plus optional distractors (random characters, controlled errors, problem revisions) designed to counter cognitive biases and logical fallacies.

The dataset is virtually unbounded, perfectly balanced (50/50 true/false), and requires no human or LLM labeling.

Logic games

Game Description
Guided Maths Scratchpad-style arithmetic (sum, product, polynomial)
Causal Clauses Causal graphs with connectivity and fork/collider questions
Context-Free Grammars String membership and grammar comparison
CLEVR Textual spatial-reasoning scenes from CLEVR-style templates

Augmentation presets

Preset Components
full Games + Errors + Characters + Revisions (GECR)
g Games only
ge Games + Errors
gec Games + Errors + Characters

Installation

pip install logicjitter

Optional: set a custom data directory for generated datasets and CLEVR downloads:

export LOGICJITTER_DATA_DIR=/path/to/data

Quick start

Generate a single logic game

from logicjitter import LogicJitter

lj = LogicJitter(multimodal=True, n_characters=3, seed=42)
print(lj.get_logic_game())
print(lj.get_logic_game(game_type="causal"))
print(lj.get_logic_game(game_type="maths"))

Build a HuggingFace dataset

from logicjitter import create_logicjitter_dataset

ds = create_logicjitter_dataset(
    n_samples=1000,
    preset="full",
    seed=42,
    output_dir="./data",
)
print(len(ds), ds[0]["ntp"])

Command line

After pip install logicjitter, use the logicjitter-generate command. While developing from a local clone, run pip install -e . first so the CLI is registered.

# Print demo samples (python -m works even without the console script)
python -m logicjitter --demo --n-samples 5 --preset full --no-multimodal

# Same via the installed entry point
logicjitter-generate --demo --n-samples 5 --preset full --no-multimodal

# Generate and save a dataset
logicjitter-generate --n-samples 1000 --preset full --output-dir ./data

Adding your own logic game

Each built-in game is a function with this signature:

def get_my_problem(error: bool = False, game_pieces: dict | None = None) -> dict:
    return {
        "problem": "...",           # statement shown in the sample
        "right_answers": ["yes"],   # phrases a correct character may say
        "wrong_answers": ["no"],    # phrases an incorrect character may say
        "game_pieces": {...},       # optional state for problem revisions
    }

When error=True, bake a mistake into the statement. When game_pieces is passed back on a revision round, update the underlying facts (e.g. change a number) while keeping the same characters.

Register the game and generate samples:

from logicjitter import LogicJitter

lj = LogicJitter(multimodal=False, seed=0)
lj.register_game("parity", get_parity_problem)
print(lj.get_logic_game(game_type="parity"))

See examples/custom_parity_game.py for a complete, runnable toy example (even/odd sums).


Package layout

logicjitter/
├── pyproject.toml
├── README.md
└── src/logicjitter/
    ├── __init__.py          # LogicJitter, create_logicjitter_dataset
    ├── cli.py               # logicjitter-generate entry point
    ├── dataset.py           # HuggingFace dataset pipeline
    ├── paths.py             # Package and cache paths
    └── creation/            # Logic game generators
        ├── logicjitter_generator.py
        ├── arithmetics_dataset.py
        ├── causal_dataset.py
        ├── cfg_dataset.py
        ├── clevr_dataset.py
        ├── clevr_tools/
        └── data/

Citation

@article{herranzcelotti2026logicjitter,
  title   = {LogicJitter: Let LLMs play and uncover misinformation},
  author  = {Herranz-Celotti, Luca and Viviani, Marco},
  journal = {Computers and Electrical Engineering},
  volume  = {136},
  pages   = {111215},
  year    = {2026},
  doi     = {10.1016/j.compeleceng.2026.111215},
  url     = {https://www.sciencedirect.com/science/article/pii/S0045790626002879}
}

License

Published under CC BY 4.0.

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

logicjitter-0.1.0.tar.gz (54.0 kB view details)

Uploaded Source

Built Distribution

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

logicjitter-0.1.0-py3-none-any.whl (61.5 kB view details)

Uploaded Python 3

File details

Details for the file logicjitter-0.1.0.tar.gz.

File metadata

  • Download URL: logicjitter-0.1.0.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for logicjitter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0011649c8f75966fdd888aa958b41f4e9b82b06c2c4dc7b405045471530e368c
MD5 61b0cca2a6804fd7097d2f70e82f2d4d
BLAKE2b-256 16c6b6c1b6a4ddfbd1a44b5f0db8b96589628929b4ab3bbaad49ea8b41f99854

See more details on using hashes here.

File details

Details for the file logicjitter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: logicjitter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 61.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for logicjitter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff20e74f705c211b7501ab9a0a2a0d62d956e975b0367627a47eda4bef2cf29f
MD5 b9278744d8515eadce7fe2a3a2fc383b
BLAKE2b-256 fc331f82fd65b81fa2b8c05a6d70fd337bd2ffb843e4f8644d707cadd78d1d16

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