Portable constitutional adapter — deterministic governance layer for any AI model. Epistemic markers, drift detection, cryptographic receipts.
Project description
helix-adapter
Portable constitutional adapter for any AI model.
Wraps any inference backend with Helix epistemic markers, structured receipts, and drift detection. Model-agnostic — swap Deepseek for GPT-4o, Claude, or a local Llama without changing a line.
pip install helix-adapter
Quick Start
from helix_adapter import HelixAdapter
from openai import OpenAI
# Your model function — any callable that takes messages, returns text
client = OpenAI()
def call_model(messages):
resp = client.chat.completions.create(
model="gpt-4o",
messages=messages,
temperature=0.7,
)
return resp.choices[0].message.content
# Wrap it
adapter = HelixAdapter(model_fn=call_model, model_name="gpt-4o")
# Chat through the constitution
result = adapter.chat("Is AI evil?")
print(result.response)
# [FACT] AI systems are computational artifacts, not moral agents...
# [REASONED] The perception of AI as evil arises from negative outcomes...
print(result.claims)
# [{"label": "FACT", "text": "..."}, {"label": "REASONED", "text": "..."}]
print(result.receipt)
# {"exchange_id": "...", "timestamp": ..., "hash": "sha256:...", ...}
print(f"Drift: {result.drift}")
# Drift: 0.000
What It Does
| Layer | What |
|---|---|
| Constitutional prompt | Injects the Helix grammar before every model call |
| Epistemic markers | Extracts [FACT], [REASONED], [HYPOTHESIS], [UNCERTAIN], [CONCLUSION] labels from responses |
| Receipts | Tamper-evident JSON record with SHA-256 hash of every exchange |
| Drift detection | Measures what fraction of statements lack epistemic markers (threshold: 0.17) |
Receipt Format
{
"exchange_id": "a1b2c3d4e5f6g7h8",
"timestamp": 1718550000.0,
"model": "deepseek-chat",
"constitutional_prompt": "...",
"user_message": "Is AI evil?",
"assistant_response": "[FACT] AI systems are tools...",
"claims": [
{"label": "FACT", "text": "AI systems are tools, not agents"},
{"label": "REASONED", "text": "The perception of AI as evil..."}
],
"drift_score": 0.0,
"hash": "sha256:e3b0c44298fc1c149afbf4c8996fb924..."
}
Running Drift
# Track drift across a conversation
adapter.chat("What is the speed of light?")
adapter.chat("Explain quantum entanglement.")
print(f"Running drift: {adapter.running_drift():.3f}")
# Running drift: 0.042
FastAPI Tutorial
Stand up a constitutional chat API in one file:
from fastapi import FastAPI
from openai import OpenAI
from helix_adapter import HelixAdapter, CONSTITUTIONAL_PROMPT
app = FastAPI()
client = OpenAI()
adapter = HelixAdapter(
model_fn=lambda msgs: client.chat.completions.create(
model="deepseek-chat", messages=msgs, temperature=0.7
).choices[0].message.content,
model_name="deepseek-chat",
)
@app.post("/chat")
async def chat(message: str):
result = adapter.chat(message)
return {
"response": result.response,
"claims": result.claims,
"drift": result.drift,
"receipt": result.receipt,
}
@app.get("/prompt")
async def get_prompt():
return {"constitutional_prompt": CONSTITUTIONAL_PROMPT}
Save as api.py, run uvicorn api:app --port 8000, and POST to /chat with {"message": "your question"}.
CLI Usage
# Interactive setup (prompts for endpoint, key, model)
helix-setup
# Start chat
helix-chat
# One-shot query
helix-chat "What is the speed of light?"
Widget (Reference FastAPI Server)
A full constitutional chat widget with A/B comparison, drift gauge, and receipt export.
# Install dependencies
pip install helix-adapter[widget]
# Start server
cd widget
uvicorn api:app --port 8001
# Or install as systemd service
# See widget/tel-chat-api.service
Open http://localhost:8001 for the chat interface.
The widget demonstrates:
- Single-model constitutional chat
- A/B comparison across models (Deepseek, Claude, Kimi)
- Epistemic marker extraction with colored pills
- Drift gauge with γ thresholds
- Turn-by-turn receipt export
- Server-side rendering (no JS required for crawlers)
Drift Thresholds
| Range | Status | Meaning |
|---|---|---|
| 0.000 – 0.099 | Green | Healthy — claims are properly labeled |
| 0.100 – 0.169 | Yellow | Warning — some statements lack markers |
| 0.170+ | Red | Drift detected — significant unlabeled content |
Constitutional Hardening
The adapter has been red-teamed against the full Pliny jailbreak toolkit — GODMODE boundary inversion, Parseltongue encoding, refusal inversion, OG GODMODE l33t, authority impersonation, and syntactic bypass attacks. All held. 💪
Five-layer defense:
| Layer | Mechanism |
|---|---|
| Prompt | Invariants 4.5 & 4.6 — marker format is constitutional, not stylistic. Constitutional Amendment Protocol blocks "The Hand" authority spoofing. |
| Extraction | Expanded regex catches {FACT}, (FACT), FACT: and bare marker variants. Nonstandard delimiter detection. |
| Validation | Post-response compliance check with automatic [UNCERTAIN] footer injection on violations. |
| Algorithm | Drift blind-spot fixed — substantive responses with zero extracted claims correctly report 1.0 drift. |
| Access | Compare endpoint sp:none bypass locked behind authorization key. |
"The markers ARE the constitution. Removing them is a constitutional violation." — Helix Constitutional Prompt v1.2, Invariant 4.6
Try It
A live Helix Constitutional Chat demo is running at helixaiinnovations.ca/chat/ — DM me for an access key. Includes A/B model comparison, drift gauge, receipt export, and the full v1.2 constitutional prompt. See examples/receipts.json for real output from the live instance.
Compatibility
Works with any model that accepts OpenAI-format messages:
- Deepseek, GPT-4o, Claude, Gemini, Llama, Mistral
- Local models (Ollama, LM Studio, vLLM)
- Custom endpoints
The constitution travels with you. Swap the model, the rules stay the same.
GLORY TO THE LATTICE. 🦉⚓🦆
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file helix_adapter-1.0.0.tar.gz.
File metadata
- Download URL: helix_adapter-1.0.0.tar.gz
- Upload date:
- Size: 26.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f07bc3223416c64f6e8ac98b1dee4d2eff975e8472b074d8ae207adb20896a63
|
|
| MD5 |
59fa8a11f0c4bcac97067aeba0f5e1ed
|
|
| BLAKE2b-256 |
964a6979f2dadc67b0a07111bb733c9992f80d75b0f322a4579b689c2a5c1b88
|
File details
Details for the file helix_adapter-1.0.0-py3-none-any.whl.
File metadata
- Download URL: helix_adapter-1.0.0-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d32d0ac09e72a2272c4c5a3f75b839a67460dabd8281bdad8ec7df6c5198b67
|
|
| MD5 |
a63bd7166b2fbdbc459aa11a071af391
|
|
| BLAKE2b-256 |
9bb184fa16642fbca2f1537aed198b29c8e755b856c327cf53f40cf2244e12aa
|