Skip to main content

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


Download files

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

Source Distribution

schema_guard_core-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

schema_guard_core-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

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

Hashes for schema_guard_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3628c4654492a2544515a361bca7041e5d76b520b3397562ef867324d92b4b52
MD5 35062453d42bd778889b40afecfb8e82
BLAKE2b-256 9d64956ede3d82021b3af5c7a6870d5c6ad85eff23b2b47f67b49d4b183e8d89

See more details on using hashes here.

Provenance

The following attestation bundles were made for schema_guard_core-0.1.0.tar.gz:

Publisher: ci.yml on NayanSrivastav/schema-guard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for schema_guard_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05ca3d18cd3b3b009a770e33f6d2429d7efd2ffcf41e563af150ca05d3871224
MD5 6a7a90590cb7d33af0a74696d631cca9
BLAKE2b-256 5f69fcb0420f7cb8c6061017296b93bbb7755aeac1e4aec6fc6bf2a107643378

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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