Skip to main content

Universal Context Package (UCP) — reference library: validation, typed models, canonical LLM rendering

Project description

ucp — Universal Context Package reference library (Python)

Reference implementation of the UCP specification (v0.1.0-draft): schema validation, typed Pydantic models, and canonical CommonMark rendering for LLM prompts with token budgeting.

pip install pyucp   # distribution "pyucp", import name "ucp"

Quickstart

import ucp

# Load and validate a package (raises ucp.UCPValidationError on failure)
pkg = ucp.load("task.ucp.json")

print(pkg.entity.title)
print(pkg.must_know[0].text)

# Canonical prompt rendering (SPEC §7.1)
prompt = ucp.render(pkg)

# Under a token budget: truncates by ascending salience, drops sections
# in the order defined by SPEC §7.2 (summary/conflicts/diff survive longest)
prompt = ucp.render(pkg, token_budget=1500)

# Validation without parsing into models
errors = ucp.iter_errors({"ucp_version": "0.1.0"})  # -> list of messages

# Referential integrity (ucp-core profile): every claim source key must exist
dangling = pkg.verify_references()  # -> [] when clean

What this library guarantees

  • Schema validation against the bundled JSON Schema (draft 2020-12), identical to specs/ucp/schema/ucp.schema.json.
  • Must-ignore semantics: unknown fields are preserved, never rejected (SPEC §6.1) — models use extra="allow".
  • Provenance enforcement: a claim without sources fails both schema validation and model parsing.
  • Deterministic rendering: the same package always renders to the same prompt, so downstream LLM behavior is reproducible.

Token counting uses a fast len(text) / 4 heuristic; pass your own counter via render(pkg, token_budget=..., count_tokens=fn) for exact budgets.

Development

pip install -e ".[dev]"
pytest

Tests run against the spec's examples/ and conformance/ suites when the repository layout is available.

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

pyucp-0.1.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

pyucp-0.1.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file pyucp-0.1.0.tar.gz.

File metadata

  • Download URL: pyucp-0.1.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyucp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 61b80bb71dc0f844ec417abf9577dec5d886748876f44e630dccf60a35ca5cf5
MD5 77af0b213180de640a35b956c38e0959
BLAKE2b-256 06027f6e2fba9af41915574e456741925e6954bf99b81cd44b7cee07a9970c13

See more details on using hashes here.

Provenance

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

Publisher: release.yml on ucpcore/ucp

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

File details

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

File metadata

  • Download URL: pyucp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyucp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6544b14495f99eef07037327b81a929e540801830bb826f718ce078bfcbb5943
MD5 f54b62cfd3b524e33024623bb4e40684
BLAKE2b-256 a5b552a3dc6a1aff470f10efe88db6ac80dd6633b68fa1ec5c70c4fe3104ec96

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyucp-0.1.0-py3-none-any.whl:

Publisher: release.yml on ucpcore/ucp

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