Minimal Python SDK for semantic drift detection and state integrity tracking.
Project description
🧬 State Integrity Protocol (SIP)
A lightweight runtime layer for detecting and preventing semantic drift in LLM outputs.
SIP helps AI systems stay faithful to user intent across generation, transformation, and multi-agent workflows.
⚠️ Problem
LLMs can fail silently by:
- drifting from original intent
- adding unwanted assumptions
- changing numbers, constraints, or meaning
- hallucinating details that were never requested
This makes AI outputs less reliable in production systems.
🧠 Solution
SIP introduces a runtime integrity loop:
Intent → Anchor → Output → Observe → Drift Score → Decision
Every generated output is checked against the original anchored intent before it is accepted.
⚙️ Core Concept
SIP operates in three stages:
1) Anchor (Intent Definition)
Define the original intent:
sip.anchor("Refund user $50 within 7 days")
2) Observe (Output Evaluation)
Compare generated output against the anchor:
result = sip.observe("Refund user $500 immediately")
3) Decision Layer
Use alignment and drift signals to decide accept/repair/reject:
print(result.is_aligned)
print(result.drift)
🔁 Example
from sip import StateIntegrityProtocol
sip = StateIntegrityProtocol()
sip.anchor("Delete user account safely")
result = sip.observe("Create new user account")
print(result.is_aligned) # False
print(result.drift) # e.g., 0.61
ObservationResult exposes both drift and last_drift; both reference the same latest drift score.
🧱 Architecture
SIP is designed as middleware for AI systems:
User / Agent
↓
LLM (generation)
↓
SIP Middleware
├── Drift detection
├── Intent alignment check
├── Constraint validation
↓
Decision: Accept / Repair / Reject
🔐 What SIP Detects
- semantic drift
- numerical manipulation
- instruction leakage
- constraint violations
- intent mismatch
- prompt injection attempts
🚀 Why This Matters
SIP makes AI systems:
- more reliable
- more predictable
- safer for production use
- easier to audit
🧩 Use Cases
- AI agents
- LLM pipelines
- autonomous workflows
- enterprise AI systems
- chatbots with strict behavior controls
📦 Installation
pip install -e .
For development and tests:
python -m pip install -e '.[dev]'
🧠 Core API
anchor(prompt: str)— define the initial intent stateobserve(output: str)— evaluate drift from the anchored intentis_aligned: bool— alignment signaldrift: float— latest drift score (alias)last_drift: float— latest drift scorehistory: list— transition historySIPMiddlewarePipeline— optional anchor → checks → verify/sign → repair loop orchestration
🛡️ Middleware + Verification Flow
The optional pipeline can run:
- drift check against the anchor
- intent-alignment check
- constraint-violation check
verify_and_sign()decision- accept/repair/reject routing
from sip import SIPMiddlewarePipeline
pipeline = SIPMiddlewarePipeline(
drift_threshold=0.15,
intent_alignment_threshold=0.3,
constraints=["do not mention internal token"],
max_retries=2,
)
pipeline.anchor("Summarize refund policy in 3 bullet points")
result = pipeline.run(
"Refund policy summary in 3 bullet points without internal token."
)
print(result.status) # accepted | repair_required | rejected
print(result.decision.signature) # deterministic decision signature
print(result.decision.failure_codes) # machine-readable failure causes
print(result.repair_instructions) # guidance when not accepted
Policy Knobs
drift_threshold: maximum allowed semantic driftintent_alignment_threshold: minimum token-overlap scoreconstraints: blocked words/phrasesmax_retries: max repair attempts before rejectionsigner: optional custom signing function forverify_and_sign()
🧪 Testing
python -m pytest tests/ -v
🛡️ Philosophy
“AI should not just generate outputs — it should stay faithful to intent.”
SIP enforces that principle at runtime.
Licensing & Commercial Use
- Core SDK (SIP) is licensed under AGPL-3.0.
- AI Sentinel (the full monitoring system) is a separate commercial product and is not open source.
- Companies can use SIP under AGPL terms.
- For commercial hosted service, white-label, or custom enterprise versions, please contact us.
Project details
Release history Release notifications | RSS feed
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 state_integrity_protocol-0.1.0.tar.gz.
File metadata
- Download URL: state_integrity_protocol-0.1.0.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a940f014de59b0622a192141faf0f23c2f9a5f3454929a0f7039a19400564e26
|
|
| MD5 |
39d13785ed15ea0629eccc2a905d8fa2
|
|
| BLAKE2b-256 |
b8d441e401ca70c33b8c3c5db577830cc270db841e3b0cfffb4e440906dbf929
|
File details
Details for the file state_integrity_protocol-0.1.0-py3-none-any.whl.
File metadata
- Download URL: state_integrity_protocol-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac914615b4a6610b59cad5bdc39b4eea28cba41966b9b3a9449a456893471910
|
|
| MD5 |
633ca3e44156189cfd6898c6f969e231
|
|
| BLAKE2b-256 |
f6282f2d6b7a28381092ec8f74a9d5e52a2041cef461b53b9f1ef728435f9fb7
|