Skip to main content

Validate JSONL records against lightweight field contracts.

Project description

jsonl-contract-check

Validate JSONL records against lightweight field contracts from the command line or from Python.

Problem

JSONL is a convenient format for prompt runs, eval traces, data cleanup jobs, and batch API results, but small shape problems can hide until a downstream script fails. This tool gives you a fast local check for required fields, basic types, nested paths, and JSON strings embedded inside a record.

Install

pip install jsonl-contract-check

For local development:

python -m venv .venv
source .venv/bin/activate
pip install -e .

Contract Format

Create a contract JSON file with a fields array:

{
  "fields": [
    { "path": "id", "type": "str" },
    { "path": "metrics.score", "type": "number" },
    { "path": "choices[0].message.content", "type": "str" },
    { "path": "raw_response", "type": "object", "parse_json": true },
    { "path": "notes", "type": "str", "required": false }
  ]
}

Supported types are any, array, bool, float, int, null, number, object, and str. Use dotted paths for nested objects and [index] notation for array items, such as choices[0].message.content.

CLI Usage

jsonl-contract-check --contract contract.json results.jsonl

Validate multiple files:

jsonl-contract-check -c contract.json runs/*.jsonl

Emit a machine-readable report:

jsonl-contract-check -c contract.json --format json results.jsonl

The command exits with:

  • 0 when every checked row passes
  • 1 when one or more records fail
  • 2 when the contract or input files cannot be read

Python Usage

from jsonl_contract_check import audit_paths, load_contract

rules = load_contract("contract.json")
result = audit_paths(["results.jsonl"], rules)

if not result.ok:
    for issue in result.issues:
        print(issue)

Example Output

Status: FAIL
Files: 1
Records: 2
Embedded JSON parsed: 1

Field coverage:
  - id: 2/2 (str, required)
  - metrics.score: 1/2 (number, required)

Issues:
  - results.jsonl:2 [missing-field] Missing required field: metrics.score.

Development

Run tests:

PYTHONPATH=src python -m unittest discover -s tests

Build the package:

python -m build

Contributing

Issues and pull requests are welcome. Keep changes focused, include tests for behavior changes, and update the README when command behavior changes.

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

jsonl_contract_check-0.2.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

jsonl_contract_check-0.2.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file jsonl_contract_check-0.2.0.tar.gz.

File metadata

  • Download URL: jsonl_contract_check-0.2.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for jsonl_contract_check-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fd86bcc4e8004332d59720302d5ef0623f2766cc39eddb316fdc8a6022d4dd23
MD5 fa9efd2db32389e4a247ad0fbb12fa17
BLAKE2b-256 8c99f28b480c449ed1b0054a6df74b9286595fe5ad98be2a3e0516b9f7a1c34b

See more details on using hashes here.

File details

Details for the file jsonl_contract_check-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonl_contract_check-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e446f71c98b9ecd8b29385fd36a212b5ddab90e186f260a8dabe35756cc7027e
MD5 4288bee3c47c5849d1e7c896bcc7f3f1
BLAKE2b-256 e1895efc3c01aada39d5ffc4afbef0a3ac4b01e8c2ede7257992207a848d37a9

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