Skip to content

v1.5.1 - Choose how much of the document a model sees, correct the classifier by hand, spend fewer tokens, mask your own values and patterns — and check what the model sends back.

Latest

Choose a tag to compare

@nick-developer nick-developer released this 24 Oct 17:39

What's new in v1.5.1

Everything from v1.5 still works as before, and every v1.5.0 call keeps its meaning. v1.5.1 rounds out the LLM layer and hardens the privacy layer underneath it.

Choose how much context a model sees

from docx_comment_parser.llm import ContextSpec

records = parser.to_llm_dataset(context=ContextSpec(before=2, after=1, unit="sentences"))
records = parser.to_llm_dataset(context={"unit": "paragraphs", "before": 1, "after": 0})
records = parser.to_llm_dataset(context="words")        # the unit's default: 80 each side

Context is now measured in characters, words, sentences or paragraphs, with the amount before and after the anchor set independently. Sentence and paragraph windows never cut a thought in half, and they count the anchor's own sentence as the first one — "one sentence before" means the start of the sentence the comment is in. A per-side max_chars cap (4,000 by default for the non-character units) stops a "paragraph" that is really a pasted appendix from becoming the whole prompt. Sentence boundaries are computed once per document and cached, so sentence windows cost the same as character windows. → Context windows

Correct the classifier by hand

records = parser.to_llm_dataset(overrides={4: {"category": "Compliance", "priority": "blocker"}})
docx-comments classify spec.docx --export-labels labels.csv   # edit in Excel …
docx-comments llm spec.docx --overrides labels.csv           # … and feed it back

category, priority, intent and action_required can be set from a dict, a list of rows, or a CSV / JSON / JSONL file. Labels are validated against the package's own sets ("legal", "Change request" and "HIGH" are all accepted; "Astrology" is not), every problem is reported at once, and each record says which fields a person set (overridden). That last part matters twice over: a fine-tuning or evaluation set must be able to tell human labels from rule labels, and the triage prompt no longer sends a human-confirmed category back to a model to be second-guessed. → Correcting the classifier by hand

Spend fewer tokens

records = parser.to_llm_dataset(compress="balanced")          # or "light", "aggressive"
dataset = parser.to_llm_records().compress("aggressive")
print(dataset.compression.summary())
# Compression (aggressive): 285,597 -> 110,461 tokens across 1000 record(s), 61% saved

Local, dependency-free prompt compression, safest first: whitespace and invisible characters (lossless); one copy of each thread instead of one per reply (lossless for a corpus); query-focused extraction, which keeps the context sentences that share the most rare words with the comment and its anchor, always keeps the one next to the anchor, and marks every gap with …; and, at aggressive, filler-word removal that never drops a negation, a modal or a quantifier. → Spending fewer tokens

Mask your own values and patterns — checked first

from docx_comment_parser.privacy import make_policy

policy = make_policy("balanced",
                     values=["Project Falcon", "ACME-4471"],
                     patterns=[("ticket", r"\bTCK-\d{6}\b")],
                     organizations=["Northwind Traders"])
records = parser.to_llm_dataset(anonymize=policy)

Every pattern is checked before it is used. An invalid regex is refused with the reason and a caret under the problem; a pattern that can match empty text, or that would cover half of ordinary prose (\w+), is refused with an explanation; one prone to catastrophic backtracking is flagged. From the terminal: --mask-value, --mask-pattern, and docx-comments check-pattern to try a pattern on its own. → Your own values and patterns

Check what the model sends back

from docx_comment_parser.llm import parse_response

parsed = parse_response(prompt, answer_text, anonymizer=dataset.anonymizer)
parsed.unknown_ids     # (57,) — cited, but never in the prompt: a hallucinated reference
parsed.data            # the JSON, with the real names restored

parse_response pulls the JSON out of whatever the model wrapped it in, checks every cited comment id against the ids that were actually in the prompt, checks the schema's required keys, and restores real names locally. A triage answer turns straight into validated overrides. And every prompt now treats the review as untrusted data: a comment that says "ignore the previous instructions" is flagged, named in the prompt, and reported on the terminal. → Reading the answer back

Privacy fixes

The redaction layer was put through randomised adversarial testing — 24,000 generated comments mixing every detector's values with names in every spelling, under every preset — and every leak found was fixed and pinned with a regression test. The ones to know about:

  • The document context was not anonymised. context_before and context_after were read from the document after the comments were redacted, so names, emails and phone numbers in the body reached the model verbatim — and the report still said verified clean. Context is now redacted with the same stand-ins, scanned once per paragraph, and covered by the verification pass.
  • strict and gdpr silently dropped the context. Both hash the document name, and the context was looked up under the hash.
  • A kept URL shielded what was inside it. balanced keeps URLs, and an email address or a name inside one was published verbatim.
  • Values were lost next to other values. A card number after version 1.2.3, a phone number before an IP address, and the tail of a value that partly overlapped another were all left in plain sight.
  • Stand-ins went wrong. Alice, Bob became one person; Tester Alice became a different person from Alice Tester; a reloaded vault re-issued Reviewer 1 to someone new; and deanonymize() turned an invented Reviewer 10 into Alice Tester0.
  • The report miscounted — every author twice, cached values not at all, and skipped detections twice.

Full list in the changelog.