Compress clinical text without losing (or flipping) clinical meaning.
Project description
clinicalcompress
Compress clinical text without flipping a negation.
"Patient denies chest pain." → a naive compressor drops "denies" → "Patient chest pain."
That single dropped word turns a normal finding into a medical emergency.
clinicalcompress is a deterministic-first Python library that compresses
clinical text for LLM context windows, storage, or transmission — while
guaranteeing that negations, values, allergies, laterality, and temporal
status markers can never be silently lost or reversed.
No API key required. The protection and verification layers are fully deterministic; LLM-assisted compression is an optional add-on.
Install
pip install clinicalcompress
Quickstart
from clinicalcompress import compress
note = "Patient denies chest pain. No history of MI. BP 120/80. Allergic to penicillin."
result = compress(note, target_reduction=0.3)
print(result.compressed_text)
print(result.safety.all_passed) # True — nothing clinically load-bearing was lost
print(result.reduction_pct) # best-effort token reduction, %
Run the built-in demo (no API key needed):
python examples/quickstart.py
It compresses a sample note, then deliberately shows a naive, unsafe
compression dropping a negation — and verify() catching the flip.
The five protected categories
clinicalcompress never drops or alters text in these categories, no
matter how aggressive the compression target is:
| Category | Example |
|---|---|
| Negation | "denies", "no", "ruled out", "without" |
| Value | "BP 120/80", "HR 88 bpm", "10 mg" |
| Allergy | "Allergic to penicillin", "NKDA" |
| Laterality | "left knee", "bilateral", "R) shoulder" |
| Temporal | "history of", "chronic", "resolved" |
The verification guarantee
This is the whole point of the library. compress(text, strict=True)
(the default) runs deterministic safety checks after every compression:
negation_preserved— every negation cue in the source is still present and still adjacent to its governed clinical term.values_intact— every numeric value + unit is present, unchanged.allergies_preserved— every allergy statement is present.laterality_preserved— every left/right/bilateral marker is present with its referent.no_meaning_reversal— no term that was negated in the source appears as an unqualified positive assertion in the output.
If any check fails, the orchestrator reverts the affected content to the
source text and re-verifies. With strict=True, the result can never
contain a lost negation or a reversed clinical meaning. This is a
guarantee the test suite enforces directly (see tests/test_verify.py
and tests/test_api.py).
Architecture
protect() → compress_deterministic() [+ optional compress_llm()] → verify() → (revert if unsafe)
- Protect (deterministic): scan the source text and mark every clinically load-bearing span before any compression happens.
- Compress (deterministic by default): remove redundancy — repeated whitespace, duplicate sentences, boilerplate filler, low-information sentences — from everything outside protected spans. LLM-assisted compression is optional, only ever touches unprotected spans, and silently no-ops without an API key.
- Verify (deterministic): confirm every protected span's meaning survived. Revert on any failure.
CLI reference
# Compress a note and print the safety report
clinicalcompress run --file note.txt --reduction 0.4
# Show what would be protected, without compressing (good for demos)
clinicalcompress check --file note.txt
# Optionally enable LLM-assisted compression of unprotected spans
clinicalcompress run --file note.txt --use-llm
API example
from clinicalcompress import compress
from clinicalcompress.protect import protect
text = "Denies fever. History of asthma. Left knee pain. BP 118/76."
spans = protect(text)
for span in spans:
print(span.category, span.text, span.governs)
result = compress(text, target_reduction=0.4, use_llm=False, strict=True)
print(result.compressed_text)
print(result.safety.checks)
Disclaimer
clinicalcompress is a text-compression utility, not a medical device.
It is not clinically validated and must not be used as the sole basis
for clinical decisions. Always review compressed output before use in
any workflow that affects patient care.
Live demo
A hosted demo showing the safe compression side-by-side against a
deliberately unsafe naive baseline lives at
versionone.health/tools/clinicalcompress.
The same UI can be run locally — see webui/README.md.
Contributing
See CONTRIBUTING.md for how to add a new protected category, add a detector, and the project's no-PHI rule.
License
Apache 2.0. See LICENSE. Copyright 2026 Anurag Chatterjee.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clinicalcompress-0.1.0.tar.gz.
File metadata
- Download URL: clinicalcompress-0.1.0.tar.gz
- Upload date:
- Size: 26.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3698c569beec36c2b360288578962648f95aeb07d7c1fb51ca919807829c2cb8
|
|
| MD5 |
8899188e0f7f9e3cb6c053985900d7ba
|
|
| BLAKE2b-256 |
a3eb256c1a5f31920fc23e8a001eaa6448e2c1fa9deeb53d6cc18239737e5b9c
|
Provenance
The following attestation bundles were made for clinicalcompress-0.1.0.tar.gz:
Publisher:
publish.yml on VersionOne-Health/clinicalcompress
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clinicalcompress-0.1.0.tar.gz -
Subject digest:
3698c569beec36c2b360288578962648f95aeb07d7c1fb51ca919807829c2cb8 - Sigstore transparency entry: 2084178978
- Sigstore integration time:
-
Permalink:
VersionOne-Health/clinicalcompress@5d73f2a7f202ace8131491a4050d52510bf2e5fa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/VersionOne-Health
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5d73f2a7f202ace8131491a4050d52510bf2e5fa -
Trigger Event:
release
-
Statement type:
File details
Details for the file clinicalcompress-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clinicalcompress-0.1.0-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
993b76f066189a55e8f7a9a6665c8f7b4e1dea63ebeb84322939d96776e4c9d4
|
|
| MD5 |
ee80d1fcc1d9df31520a4571e2e79bcd
|
|
| BLAKE2b-256 |
b86c8b140968076527a12365bf2fe59803271e833af9d5bddc7330b87811e593
|
Provenance
The following attestation bundles were made for clinicalcompress-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on VersionOne-Health/clinicalcompress
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clinicalcompress-0.1.0-py3-none-any.whl -
Subject digest:
993b76f066189a55e8f7a9a6665c8f7b4e1dea63ebeb84322939d96776e4c9d4 - Sigstore transparency entry: 2084178995
- Sigstore integration time:
-
Permalink:
VersionOne-Health/clinicalcompress@5d73f2a7f202ace8131491a4050d52510bf2e5fa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/VersionOne-Health
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5d73f2a7f202ace8131491a4050d52510bf2e5fa -
Trigger Event:
release
-
Statement type: