Open-source middleware that validates AI outputs before they reach your database.
Project description
iron-thread
Open‑source middleware that validates AI outputs before they reach your database.
Install
pip install iron-thread
Quick Start
from ironthread import IronThread
it = IronThread()
# Create a schema
schema = it.create_schema(
name="User Profile",
schema_definition={
"required": ["name", "email", "age"],
"properties": {
"name": {"type": "string"},
"email": {"type": "string"},
"age": {"type": "integer"}
}
}
)
# Validate any AI output (auto_correct enabled)
result = it.validate(
ai_output='{"name": "John", "email": "john@example.com", "age": 28}',
schema_id=schema["id"],
auto_correct=True
)
if result.passed:
print("Clean — safe to send to database")
print(result.data)
print(f"Confidence: {result.confidence_score}")
else:
print(f"Blocked — {result.reason}")
Real World Usage
import openai
from ironthread import IronThread
it = IronThread()
client = openai.OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Generate a user profile as JSON"}]
)
ai_output = response.choices[0].message.content
# Validate before touching your database
result = it.validate(
ai_output=ai_output,
schema_id="your-schema-id",
model_used="gpt-4",
auto_correct=True
)
if result.passed:
db.save(result.data) # safe
else:
print(f"AI output rejected: {result.reason}")
API
IronThread(host=None)
Initialize the client. Defaults to https://iron-thread.onrender.com.
.create_schema(name, schema_definition, description="")
Create a validation schema. Returns the schema with its id.
.validate(ai_output, schema_id, model_used=None, auto_correct=False)
Validate AI output against a schema. Returns a ValidationResult.
Set auto_correct=True to automatically fix common JSON errors.
.validate_batch(ai_outputs, schema_id, model_used=None)
Validate multiple outputs at once. Returns a BatchValidationResult.
.verify_run(run_id)
Check the tamper‑evident hash of a validation run.
.get_schema_chain(schema_id)
Get the full hash chain for a schema (audit trail).
.stats()
Get dashboard stats — total runs, pass rate, avg latency.
.runs()
Get the last 50 validation runs.
ValidationResult (v0.3.0)
result.passed # True or False
result.status # "passed" / "failed" / "corrected"
result.reason # why it failed (if it did)
result.data # the clean validated output
result.auto_corrected # whether auto‑correction was applied
result.attempts # number of correction attempts
result.confidence_score # 0–1 confidence in the result
result.confidence_flags # list of warnings (e.g., ['low_confidence'])
result.latency_ms # how long validation took
result.run_id # ID of this run in the database
BatchValidationResult
batch.total # total inputs
batch.passed # count passed
batch.failed # count failed
batch.corrected # count auto‑corrected
batch.success_rate # percentage passed (0‑100)
batch.results # list of ValidationResult objects
Links
- API Docs: https://iron-thread.onrender.com/docs
- GitHub: https://github.com/eugene001dayne/iron-thread
- JavaScript SDK: https://www.npmjs.com/package/iron-thread
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 iron_thread-0.3.0.tar.gz.
File metadata
- Download URL: iron_thread-0.3.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b64464e37c3bbc01f0f8db252974c3b1295823b47e243f6370faac9cbb45a3f6
|
|
| MD5 |
8c7bdb6f3b2a39464d1e5c445d2680bc
|
|
| BLAKE2b-256 |
c8d38d7fa69b8c3c7d885d775a77df840401ed2d3ba34577d377ef78299f0544
|
File details
Details for the file iron_thread-0.3.0-py3-none-any.whl.
File metadata
- Download URL: iron_thread-0.3.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a38bdc50cacfc5df6321ef8dfad29d2a1baa58f18bcb903ee37c294c4a9b0918
|
|
| MD5 |
0cb4d20fc739f9e879034af193eca07d
|
|
| BLAKE2b-256 |
64c97ab3510737d41790392e8a9b2d46529cbe699b0da2745e75e0b0e19fc201
|