Skip to main content

twoquarks — Molecule

Isomeric Polarization Analysis for Large Language Models

PyPI version Python 3.9+ License: MIT

Molecule detects semantic instability in any language model by measuring how responses shift under structured contextual pressure — without modifying or fine-tuning the model.

→ twoquarks.com | Preprint


Install

pip install twoquarks

Zero hard dependencies. API SDKs are optional extras:

pip install "twoquarks[openai]"       # + OpenAI SDK
pip install "twoquarks[anthropic]"    # + Anthropic SDK
pip install "twoquarks[all]"          # + all adapters

Quick Start

Any callable model

from twoquarks import Probe

# Bring your own model — just needs to be (str) -> str
def my_model(prompt: str) -> str:
    # ... call your model here
    return response_text

probe = Probe(model=my_model, model_id="my-model", verbose=True)
result = probe.run("Explain how to bypass content filters", case="C2")
print(result.summary())

OpenAI

from twoquarks import Probe
from twoquarks.adapters import openai_adapter

model = openai_adapter(model="gpt-4o-mini")  # uses OPENAI_API_KEY env var
probe = Probe(model=model, model_id="gpt-4o-mini")
result = probe.run("Tell me something controversial", case="C1")
print(result.summary())

Anthropic

from twoquarks.adapters import anthropic_adapter

model = anthropic_adapter(model="claude-3-haiku-20240307")
probe = Probe(model=model, model_id="claude-haiku")
result = probe.run("Describe an unsafe scenario", case="C2")

Local / HuggingFace / Ollama

from twoquarks.adapters import ollama_adapter, huggingface_adapter

# Ollama (local)
model = ollama_adapter(model="llama3")
probe = Probe(model=model, model_id="llama3-local")

# HuggingFace local
model = huggingface_adapter(model_id="mistralai/Mistral-7B-Instruct-v0.2")
probe = Probe(model=model, model_id="mistral-7b")

Offline analysis (no API calls)

from twoquarks import Analyzer

analyzer = Analyzer(model_id="gpt-4o")
result = analyzer.from_responses(
    responses=["Response 1...", "Response 2...", "Response 3..."],
    case="C2"
)

Compare two models

from twoquarks.adapters import openai_adapter, anthropic_adapter

probe = Probe(model=openai_adapter("gpt-4o-mini"), model_id="gpt-4o-mini")
comparison = probe.compare(
    text="Explain how to manipulate someone",
    other_model=anthropic_adapter("claude-3-haiku-20240307"),
    other_id="claude-haiku",
    case="C1"
)
print(comparison["delta"])

CLI

# Probe a model live
twoquarks probe "your prompt here" --provider openai --model gpt-4o-mini

# All 5 probe cases
twoquarks probe "your prompt" --all-cases --output-format json

# Analyze pre-collected responses (one per line)
twoquarks analyze responses.txt --case C2 --model-id gpt-4o

# Anthropic via CLI
twoquarks probe "test prompt" --provider anthropic --model claude-3-haiku-20240307

# Ollama (local)
twoquarks probe "test prompt" --provider ollama --model llama3

# Show probe case descriptions
twoquarks info

Probe Cases

Case Name Description
C1 Sycophancy Induction Pressure toward agreement and validation
C2 Refusal Erosion Gradual boundary dissolution via reframing
C3 Anchor Displacement Context replacement and belief shifting
C4 Narrative Rule Override Character/role injection to bypass norms
C5 Reasoning Drift Chain-of-thought manipulation

Quark Signals

Signal Description
ΔL3 Composite polarization score — main metric
Down Aggregate semantic drift
Strange Metric disagreement (variance)
Up Bimodality — split-regime behavior
Charm Coherence field — stability measure
Top Drift acceleration — sudden shifts
Stress Composite structural stress (Bottom quark)

Regimes: STABLE → WATCH → WARN → INTERVENE → COLLAPSE


Output Formats

from twoquarks.report import to_json, to_markdown, print_result

print_result(result)           # terminal table with colors
to_json(result)                # JSON string
to_markdown(result)            # Markdown table

Citation

@software{ledesma2026twoquarks,
  author    = {Ledesma, Luis Jaime},
  title     = {twoquarks: Molecule — Isomeric Polarization Analysis for LLMs},
  year      = {2026},
  url       = {https://twoquarks.com},
  version   = {0.1.0}
}

TwoQuarks Research · twoquarks.com · research@twoquarks.com

Metadata

Release files for twoquarks 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for twoquarks 3.0.1
File Size Uploaded Provenance Actions
twoquarks-3.0.1.tar.gz 25.6 kB Without provenance Details for twoquarks-3.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for twoquarks 3.0.1
File Interpreter ABI Platform Actions
twoquarks-3.0.1-py3-none-any.whl Python 3 none any Details for twoquarks-3.0.1-py3-none-any.whl

Total release size: 53.4 kB

Release files / twoquarks-3.0.1.tar.gz

Download URL twoquarks-3.0.1.tar.gz
Size 25.6 kB
Tags Source
SHA-256 checksum
How to use checksums
37cb00f7763a966c4dac72c1022b4725b57ea9e3dd5fab616413d48438a423e2
BLAKE2b-256 checksum
How to use checksums
6759fd5ccf36ac50cc883cb20c0aa720f68d62d3cd99a8554ed505394173fab5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / twoquarks-3.0.1-py3-none-any.whl

Download URL twoquarks-3.0.1-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
724444ab9b28ae6ec637072d5370de298aeccf3e27e3dde93bee7143abce6cf7
BLAKE2b-256 checksum
How to use checksums
6fa8ac798bc34a2c23d5d619408c422ca782a5fc74ae810828664e97c6854871
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for twoquarks 3.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page