Structured Output Validator & Schema Enforcer SDK
Project description
SchemaGuard Python SDK
The official Python client for SchemaGuard — a runtime validation, monitoring, and coercion engine for protecting your LLM pipelines from bad JSON schemas.
Installation
pip install schemaguard
Quick Start (Offline Mode)
If you don't want to run the core Golang server, use the LocalValidator to catch schema drifts natively with exactly mapped formatting constraints dynamically directly in your Python code environments.
from schemaguard import LocalValidator
schema = {
"type": "object",
"properties": { "id": {"type": "integer"} },
"required": ["id"]
}
validator = LocalValidator(schema)
llm_response = '```json\n{"id": 123}\n```'
is_valid, data, errors = validator.validate(llm_response)
if is_valid:
print("Clean format!", data["id"])
else:
print("Errors:", errors)
Production Mode (API Client)
In production, SchemaGuard manages schema distribution caching, active OpenTelemetry cost tracking, and circuit breakers directly locally or on your private clusters utilizing our blazingly fast Golang engine.
from schemaguard import SchemaGuardClient
client = SchemaGuardClient(api_key="sg_...", base_url="http://localhost:8080/v1")
res = client.validate(schema_name="invoice_schema", version="latest", payload='{"total": "-10"}')
if not res.get("status") == "PASS":
print(res["errors"]) # Maps dynamically cleanly for prompt re-injection strategies
LangChain Integration
Using our native parser natively integrates into LangChain's existing RetryingOutputParser bounds without needing human configurations.
from schemaguard_parser import SchemaGuardOutputParser
parser = SchemaGuardOutputParser(schema_dict=schema)
prompt = PromptTemplate(
template="Extract invoice details.\n{format_instructions}\n{context}",
input_variables=["context"],
partial_variables={"format_instructions": parser.get_format_instructions()},
)
chain = prompt | llm | parser
# Automatically drops schema bounds into the prompt, extracts response payloads, validates constraints, and natively rejects outputs throwing `OutputParserException`.
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 schema_guard_core-0.1.0.tar.gz.
File metadata
- Download URL: schema_guard_core-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3628c4654492a2544515a361bca7041e5d76b520b3397562ef867324d92b4b52
|
|
| MD5 |
35062453d42bd778889b40afecfb8e82
|
|
| BLAKE2b-256 |
9d64956ede3d82021b3af5c7a6870d5c6ad85eff23b2b47f67b49d4b183e8d89
|
Provenance
The following attestation bundles were made for schema_guard_core-0.1.0.tar.gz:
Publisher:
ci.yml on NayanSrivastav/schema-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
schema_guard_core-0.1.0.tar.gz -
Subject digest:
3628c4654492a2544515a361bca7041e5d76b520b3397562ef867324d92b4b52 - Sigstore transparency entry: 1178846978
- Sigstore integration time:
-
Permalink:
NayanSrivastav/schema-guard@05fea929c6ccb679f2d1c8fd13776c40d9ea78a8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/NayanSrivastav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@05fea929c6ccb679f2d1c8fd13776c40d9ea78a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file schema_guard_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: schema_guard_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05ca3d18cd3b3b009a770e33f6d2429d7efd2ffcf41e563af150ca05d3871224
|
|
| MD5 |
6a7a90590cb7d33af0a74696d631cca9
|
|
| BLAKE2b-256 |
5f69fcb0420f7cb8c6061017296b93bbb7755aeac1e4aec6fc6bf2a107643378
|
Provenance
The following attestation bundles were made for schema_guard_core-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on NayanSrivastav/schema-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
schema_guard_core-0.1.0-py3-none-any.whl -
Subject digest:
05ca3d18cd3b3b009a770e33f6d2429d7efd2ffcf41e563af150ca05d3871224 - Sigstore transparency entry: 1178846979
- Sigstore integration time:
-
Permalink:
NayanSrivastav/schema-guard@05fea929c6ccb679f2d1c8fd13776c40d9ea78a8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/NayanSrivastav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@05fea929c6ccb679f2d1c8fd13776c40d9ea78a8 -
Trigger Event:
push
-
Statement type: