How hotragn/schemaport works
Purpose and operating boundary
Schemaport is an offline Python preflight checker for AI-provider request JSON. It validates provider/model-specific request contracts and prompt-cache safety without sending requests, managing credentials, or calling external APIs. Its output is intended for developers, CI, and agent check-fix-recheck loops.
Core public package boundary: src/schemaport/__init__.py, src/schemaport/contracts.py, src/schemaport/model.py.
Entry points and invocation
The command-line entry point reads a JSON request file, requires a target model, optionally resolves an API surface, renders findings, and maps outcomes to process exit codes. Python callers use check() for parsed dictionaries or check_file() for files.
Paths: src/schemaport/__main__.py, src/schemaport/cli.py, src/schemaport/__init__.py.
Check orchestration
The engine is the central control-flow coordinator: load/select model profile and surface, run applicable analyzers against the immutable input request, aggregate structured findings into a report, and distinguish validation findings from operational errors (bad file/JSON/unknown model).
Paths: src/schemaport/engine.py, src/schemaport/errors.py, src/schemaport/model.py.
Primary flow is: request JSON + explicit model → profile/surface resolution → analyzer execution → report → text/JSON/SARIF serialization or Python result. The checker never crosses into provider transport.
Versioned contract-data layer
Rules are data-driven rather than hard-coded. The packaged dataset defines coverage, model/API-surface profiles, rule sets, severity/remediation, and evidence provenance. This separation lets provider-contract updates ship as audited package data while keeping analysis mechanics stable.
Paths: src/schemaport/data/dataset.json, src/schemaport/data/profiles/openai-responses.json, src/schemaport/data/rule-sets/anthropic-messages.json.
Profiles cover Anthropic Messages and OpenAI Responses/Chat Completions surfaces; ambiguous surface selection is an explicit safety boundary rather than silently applying potentially wrong rules.
Analysis stages
Structured-output analysis traverses provider request structures and applies supported-JSON-Schema and request-shape rules. Cache-safety analysis examines prompt/request ordering and detects content likely to disrupt prefix caching. Findings carry rule ID, severity, JSON path, explanation, remediation, and evidence basis.
Paths: src/schemaport/analyzers/structured_output.py, src/schemaport/analyzers/cache_safety.py, src/schemaport/shapes.py.
shapes.py likely centralizes traversal/path or schema-shape representation used to consistently pinpoint locations in arbitrary request JSON.
Findings and reporting interfaces
The internal report model is rendered through three stable consumer interfaces: human-readable terminal text, machine-readable JSON for scripts/agents, and SARIF for code-scanning systems. Output format and exit threshold make the same engine usable interactively and as a CI quality gate.
Paths: src/schemaport/reporters/text.py, src/schemaport/reporters/json_report.py, src/schemaport/reporters/sarif.py.
Runtime, packaging, and release integrity
Runtime is Python 3.10+ with no nonstandard dependencies. Contract data is bundled under the importable package, supporting deterministic offline execution. CI and release workflows protect the package; a dedicated contract-drift workflow plus data verifier indicate that contract-data correctness is a first-class release concern.
Paths: pyproject.toml, .github/workflows/contract-drift.yml, tools/verify_contract_data.py.
Main entry points: engine.py Check engine · contracts.py Public contracts · model.py Profile selection · structured_output.py Structured-output analysis
Components 19
Invocation
- CLI · Reads request files, selects output, and maps outcomes to exit codes.
src/schemaport/cli.py - Module entry point
src/schemaport/__main__.py - Python API · Exposes check() and check_file() callers.
src/schemaport/__init__.py
Checking Engine
- Check engine · Separates validation findings from operational errors.
src/schemaport/engine.py - Profile selection · Resolves explicit model and API surface, rejecting ambiguity.
src/schemaport/model.py - Operational errors
src/schemaport/errors.py - Public contracts
src/schemaport/contracts.py - Structured-output analysis · Checks request shape and supported JSON Schema.
src/schemaport/analyzers/structured_output.py - Cache-safety analysis · Detects prompt ordering and content that disrupt prefix caching.
src/schemaport/analyzers/cache_safety.py - Request shape traversal · Provides consistent JSON-path location handling.
src/schemaport/shapes.py
Contract Data
Versioned package data drives provider-specific validation.
- Coverage dataset · Defines coverage, rules, severity, remediation, and evidence.
src/schemaport/data/dataset.json - OpenAI surface profile
src/schemaport/data/profiles/openai-responses.json - Anthropic rule set
src/schemaport/data/rule-sets/anthropic-messages.json
Results
- Terminal text
src/schemaport/reporters/text.py - JSON output · Machine-readable output for scripts and agents.
src/schemaport/reporters/json_report.py - SARIF output · Code-scanning interchange output.
src/schemaport/reporters/sarif.py
Release Integrity
- Package definition · Bundles offline Python runtime and contract data.
pyproject.toml - Contract-data verifier
tools/verify_contract_data.py - Contract-drift CI · Guards contract-data correctness during release.
.github/workflows/contract-drift.yml
Connections 19
- Module entry point → CLI: launches
- CLI → Check engine: checks request file
- Python API → Check engine: checks dictionaries/files
- Check engine → Profile selection: resolves model and surface
- Check engine → Structured-output analysis: runs
- Check engine → Cache-safety analysis: runs
- Check engine → Operational errors: returns operational errors
- Check engine → Public contracts: produces report contracts
- Profile selection → Coverage dataset: loads coverage
- Profile selection → OpenAI surface profile: selects surface profile
- Structured-output analysis → Anthropic rule set: applies rules
- Structured-output analysis → Request shape traversal: traverses request
- Cache-safety analysis → Request shape traversal: locates findings
- Public contracts → Terminal text: renders
- Public contracts → JSON output: serializes
- Public contracts → SARIF output: serializes
- Package definition → Coverage dataset: bundles
- Contract-data verifier → Coverage dataset: verifies
- Contract-drift CI → Contract-data verifier: runs