Metadata-Version: 2.4
Name: contextbom
Version: 0.1.0
Summary: ContextBOM (CBOM) — a bill of materials for every prompt. Record where every piece of your AI model's context came from.
Project-URL: Homepage, https://github.com/contextbom/contextbom
Project-URL: Repository, https://github.com/contextbom/contextbom
Project-URL: Specification, https://github.com/contextbom/contextbom/blob/main/SPEC.md
Author: Akshat
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: ai,audit,bill-of-materials,cbom,context,context-engineering,llm,provenance
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Security
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# contextbom

**A bill of materials for every prompt.** Know exactly what went into your AI model — every source, every transformation, every redaction — as a signed, auditable manifest.

![cbom view demo](docs/demo.gif)

```
pip install contextbom
```

```python
import contextbom as cbom
from openai import OpenAI

ctx = cbom.Context()

# Stamp provenance as you gather context
docs = ctx.add(retriever.search(query), source="qdrant://kb/policies", sensitivity="internal")
history = ctx.add(memory.recall(user_id), source="mem0://user/123", sensitivity="pii")
ticket = ctx.add(fetch_ticket(id), source="https://jira.co/T-42", transform=cbom.redact_pii)

# Call any model — the manifest is generated automatically
response = ctx.complete(OpenAI(), model="gpt-5", messages=build_prompt(docs, history, ticket))

print(ctx.manifest.to_json())   # full lineage of everything the model saw
```

Output — a **CBOM manifest** for that call:

```json
{
  "cbom_version": "0.1",
  "call_id": "0198f3a2-...",
  "model": "gpt-5",
  "segments": [
    {
      "source": "qdrant://kb/policies",
      "hash": "sha256:9f2c...",
      "sensitivity": "internal",
      "transforms": [],
      "tokens": 812
    },
    {
      "source": "https://jira.co/T-42",
      "hash": "sha256:41ab...",
      "sensitivity": "internal",
      "transforms": [{"type": "redact_pii", "removed": 3}],
      "tokens": 240
    }
  ],
  "signature": "..."
}
```

## Why

- **Audit & compliance** — EU AI Act Article 12 requires logging what high-risk AI systems processed. A CBOM manifest is that record.
- **Security** — see exactly which tool output entered the prompt when investigating an injection or leak. Prove secrets never left the boundary.
- **Debugging** — "why did the model say that?" starts with "what did the model see?"
- **Trust** — signed manifests make AI decisions explainable to auditors, customers, and courts.

## What it is / isn't

| | |
|---|---|
| ✅ An open spec (JSON) + SDKs that stamp provenance onto context at assembly time | ❌ A gateway or proxy you must deploy |
| ✅ Works with any model, any framework | ❌ Another agent framework |
| ✅ Complements CycloneDX ML-BOM / SPDX (static artifacts) with runtime lineage | ❌ A replacement for SBOM standards |
| ✅ Exports over OpenTelemetry | ❌ A hosted service |

## Features

- **`cbom.Context`** — wrap context assembly; automatic manifest generation
- **Transforms** — built-in, recordable `redact_pii`, `strip_secrets`, `summarize`, `truncate`
- **`cbom view`** — CLI (installed with the package) that renders any prompt color-coded by source and sensitivity
- **Signing** — optional Sigstore-style attestation of manifests
- **Exporters** — OTel, JSONL audit log, webhook
- **Integrations** — LangChain, LlamaIndex, MCP middleware (roadmap)

## Spec

The manifest format is defined in [SPEC.md](./SPEC.md). v0.1 is deliberately small: segments, sources, hashes, transforms, sensitivity labels, signatures. Extensions are namespaced.

## Contributing

The spec is developed in the open — issues and RFCs welcome. Good first contributions: SDK ports (TypeScript, Go), framework integrations, transform plugins.

Apache-2.0.
