Skip to main content

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 state
  • observe(output: str) — evaluate drift from the anchored intent
  • is_aligned: bool — alignment signal
  • drift: float — latest drift score (alias)
  • last_drift: float — latest drift score
  • history: list — transition history
  • SIPMiddlewarePipeline — optional anchor → checks → verify/sign → repair loop orchestration

🛡️ Middleware + Verification Flow

The optional pipeline can run:

  1. drift check against the anchor
  2. intent-alignment check
  3. constraint-violation check
  4. verify_and_sign() decision
  5. 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 drift
  • intent_alignment_threshold: minimum token-overlap score
  • constraints: blocked words/phrases
  • max_retries: max repair attempts before rejection
  • signer: optional custom signing function for verify_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

state_integrity_protocol-0.1.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

state_integrity_protocol-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for state_integrity_protocol-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a940f014de59b0622a192141faf0f23c2f9a5f3454929a0f7039a19400564e26
MD5 39d13785ed15ea0629eccc2a905d8fa2
BLAKE2b-256 b8d441e401ca70c33b8c3c5db577830cc270db841e3b0cfffb4e440906dbf929

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for state_integrity_protocol-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac914615b4a6610b59cad5bdc39b4eea28cba41966b9b3a9449a456893471910
MD5 633ca3e44156189cfd6898c6f969e231
BLAKE2b-256 f6282f2d6b7a28381092ec8f74a9d5e52a2041cef461b53b9f1ef728435f9fb7

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