Andrew Fribush

← All posts

Use the LLM as a Detector, Not a Rewriter

· February 1, 2027 · 7 min read

A trainee evaluation comes in with a free-text comment. The roster has the trainee as Bradford and the evaluator as Christopher. The comment opens "Bradford ran the board well tonight," goes on "Brad caught the missed potassium before Katie on nursing flagged it," and ends with "-Chris" on its own line. (The comment is made up. The names are the examples from the prompt quoted below.) Before comments like this can be shared, Bradford, Brad, Katie and Chris all have to become [NAME], and every other word has to stay where it was.

I built the sanitizer that does this, in a backend that stores clinical training evaluations. The first plan had a model rewrite each comment without the names and then ran a regex to catch what it missed. The design I shipped runs the regex first and asks the model only which person names are left, as a JSON array of strings, and code does every replacement. The reason is what a failure looks like. When the rewriter misses a name, the name comes back inside a new document that also carries the model's other edits, and nothing marks which words it touched. When the detector misses one, a string is absent from a short list, and when the call fails outright the code logs a warning and gets an empty list.

The evidence here is the sanitization plan, the design notes for the shipped pipeline, and the module that implements it, which I ran on the made-up comment above with the model's replies stubbed. It's client work, so no real comment appears.

fig. 2.38.1 · the first plan had a model rewrite each comment, so a missed name came back inside the model’s new document; the shipped design asks the model only which names are left, so a miss is a string absent from a list and a failed call is an empty list and a warning.
THE REWRITER’S MISS HIDES IN A NEW DOCUMENT; THE DETECTOR’S MISS IS A STRINGABSENT FROM A SHORT LISTONE DOT IS ONE PASS. THE LINE IS THE COMMENT’S TEXT: INK WHERE CODE WROTE IT,ACCENT ONCE THE MODEL HAS.FIRST PLANmodel, then regexCOMMENTBradford … Brad … Katie … -ChrisMODEL REWRITES ITLLM anonymization, local endpointREGEX ON ROSTER NAMESlearner/evaluator name parts → [NAME]Dr. [NAME] → [NAME]STORED“preserves: locations, medicalterminology, training levels,procedures, shift types”WHERE A MISS ENDS UPA missed name comes back inside a newdocument that also carries themodel’s other edits. Nothing markswhich words it touched.SHIPPEDregex, then detector, then codeCOMMENTBradford … Brad … Katie … -ChrisREGEX ON ROSTER NAMESname parts → [NAME], longest firstDr. Mr. Ms. Mrs. Prof. [NAME] →[NAME]REGEX ON TITLES, SIGN-OFFSDr. Newton → [NAME]-Chris on its own line → [NAME]DETECTOR: WHICH NAMES ARE LEFT?temperature 0, 30 s timeout→ ["Brad", "Katie"]↳ error, timeout, bad JSON → [] and awarningCODE REPLACES EACH WORDreturned word → [NAME], every matchSTOREDwhitespace normalizedWHERE A MISS ENDS UPA missed name is a string absent froma short list. A failed call is anempty list and a log line, and thecomment keeps its regex output.

source: Client repo: docs/comment-sanitization-plan.md lines 84-92 (first plan); CLAUDE.md line 277 (shipped design); services/anonymize.py lines 20-257 (regex 20-107, detector 110-173, replacer 176-206, order 243-257) · detectorNotRewriter.data.ts

The First Plan Asked the Model to Rewrite

The plan had two passes. A model anonymizes the comment through an OpenAI-compatible API on a local endpoint. Then a regex replaces the learner's and evaluator's name parts with [NAME] and collapses "Dr. [NAME]" to [NAME]. The plan also lists what the output must preserve: locations, medical terminology, training levels, procedures and shift types.

That list is the set of things a rewriter can change. A model asked to return the comment without names returns a whole comment, and in doing that it can rephrase a clinical observation, soften a criticism, or drop a sentence it reads as identifying. The plan states that list as a property of the output, and no step in it compares the output to the input to see whether the list held. The regex after the model knows only the roster names, so a nickname the model left in goes through.

The Shipped Design Asks Which Names Are Left

The regex runs first. It splits each formal name ("Last, First" or "First Last") into parts longer than two characters and replaces each part on word boundaries, ignoring case, longest part first. Then it collapses Dr., Mr., Ms., Mrs. and Prof. in front of [NAME]. Two more regex passes follow before any model call. A title followed by a capitalized word of three or more letters becomes [NAME], which catches "Dr. Newton". A dash and one word on its own line becomes [NAME], and so does a bare word on its own line that matches the start of a known name part. On the example comment those passes take out Bradford and the "-Chris" sign-off and leave Brad and Katie:

text
[NAME] ran the board well tonight. Brad caught the missed potassium before Katie on nursing flagged it, and his handoff to the resident was clean.[NAME]

Then the detector gets the partly sanitized text and both formal names. The formal names are in the prompt so it can reason about nicknames and spelling variants, Brad for Bradford. This is the instruction part of the prompt, verbatim from the module:

text
Your job is to find any REMAINING person names that were missed, including:- Nicknames or diminutives of the trainee/evaluator (e.g. Brad for Bradford, Chris for Christopher, Katie for Katherine)- Spelling variants (e.g. Sarah for Sara, Allison for Alison)- The evaluator signing their name (e.g. '-Chris' at the end)- Names of OTHER people mentioned (other doctors, staff, etc.)Return ONLY a JSON array of the name strings found. If no names remain, return [].ONLY include actual human first names or last names.Do NOT include [NAME] tokens. Do NOT include titles (Dr., Mr., Ms.) in the names.Do NOT include job titles (consultant, attending, resident, nurse, etc.).Do NOT include place names, department names, medical instruments, or non-person entities.

The call runs at temperature 0 with a 30-second timeout. The code cuts everything up to a </think> or [/THINK] tag and strips a markdown code fence if the reply has them, before parsing. The parsed value has to be a list, and only strings longer than two characters are kept. A request error, a missing key in the response, or a JSON parse error logs a warning and returns an empty list.

The replacer does the editing. For each returned string it strips a leading title, splits the rest into words longer than two characters, and replaces every occurrence of each word on word boundaries, ignoring case, longest first. It collapses titles in front of [NAME] once more, and the last step normalizes whitespace. This is a reduction of the detector and the replacer (the module is longer):

Python
def detect(text, learner, evaluator):    try:        r = requests.post(API_URL, timeout=30, json={"model": MODEL, "temperature": 0,            "messages": [{"role": "user", "content": prompt(text, learner, evaluator)}]})        r.raise_for_status()        names = json.loads(strip_think_and_fences(r.json()["choices"][0]["message"]["content"]))        if isinstance(names, list):            return [n for n in names if isinstance(n, str) and len(n) > 2]    except (requests.RequestException, json.JSONDecodeError, KeyError, IndexError) as e:        log.warning("LLM name identification failed: %s", e)    return []def replace(text, names):    words = {w for n in names for w in strip_title(n).split() if len(w) > 2}    for w in sorted(words, key=len, reverse=True):        text = re.sub(r"\b" + re.escape(w) + r"\b", "[NAME]", text, flags=re.I)    return text

With the model's reply stubbed as a think block followed by a fenced ["Brad", "Katie"], the real module returns:

text
[NAME] ran the board well tonight. [NAME] caught the missed potassium before [NAME] on nursing flagged it, and his handoff to the resident was clean.[NAME]

What a Failure Looks Like in Each Design

In the rewriter design, a missed name sits inside text the model also edited. A reviewer can't diff the output against the input to find the model's work, because the model's work is the whole output. The regex pass after it catches only the names it was given. So a nickname that slips through arrives mixed in with whatever else the model changed, and nothing in the pipeline records that anything was missed.

In the detector design, a missed name is a string missing from a list. The final text is the regex output with a few more words swapped for [NAME], plus the title collapse and the whitespace normalization. Diff the two and every other change is a [NAME] where a returned word stood. So when a reviewer sees "Katie" still in a comment, the model didn't return it. The model never edits the text, and whatever it returns goes to the replacer, which does the substituting.

A total failure is an empty list. When I stubbed the reply as not json, the module logged LLM name identification failed: Expecting value: line 1 column 1 (char 0) and returned [], so the comment kept its regex output. A reply that parses but isn't a list, such as the bare string "Brad", also returns []. In both cases the code treats the result as "no additional names" and the text after the regex passes is what gets stored.

The exclusion list is the detector's precision control. The replacer acts on every occurrence of a returned word in the comment, ignoring case. If the model returned "resident", the replacer would turn every "resident" into [NAME], and training levels are on the plan's list of things to preserve. So the prompt rules out titles, job titles (consultant, attending, resident, nurse), place names, department names, medical instruments and non-person entities. In the rewriter design the model's precision and its output were the same document, and there was no separate place to put that rule.

fig. 2.38.2 · the detector prompt’s seven exclusions: each a word the replacer would blank if the model returned it.
THE DETECTOR PROMPT RULES OUT SEVEN THINGS, EACH A WORD THE REPLACER WOULDBLANKONE ROW IS ONE EXCLUSION IN THE PROMPT. A RETURNED WORD BECOMES [NAME] AT EVERYWHOLE-WORD MATCH, ANY CASE. ACCENT: WHAT IT WOULD BLANK.MUST NOT RETURNIF RETURNED, BECOMES [NAME]PLAN SAYS KEEP[NAME] tokensprompt line 133every [NAME] token—titles (Dr., Mr., Ms.)prompt line 133every “Dr.”, “Mr.” and “Ms.”—job titles (consultant,attending, resident, nurse,etc.)prompt line 134every “resident”“his handoff to the [NAME] wasclean”TRAININGLEVELSplace namesprompt line 135every match of the placeLOCATIONSdepartment namesprompt line 135every “nursing”“before Katie on [NAME] flaggedit”LOCATIONSmedical instrumentsprompt line 135every match of the instrumentMEDICALTERMINOLOGYnon-person entitiesprompt line 135every “potassium”“caught the missed [NAME] before”MEDICALTERMINOLOGY

source: Client repo: services/anonymize.py lines 131-135 (exclusions), 182 and 200-202 (replacer); docs/comment-sanitization-plan.md line 92 (preserve list); examples are the essay’s made-up comment run through replace_identified_names() · detectorNotRewriter.data.ts

Give the Model the Question With the Small Answer

The detector's output is a short list of strings. Code can check its type, drop the entries of two characters or fewer, log it, and act on one entry at a time. A rewriter's output is a new comment, and the only check on a new comment is a person reading it against the old one.

Testing for empty results is about empty values passing through a pipeline with nothing counting them. Here the failed call's empty list is logged as a warning.

Andrew Fribush, software and computer engineer in Austin. I build consequential systems where software meets institutions: finance, healthcare, commerce, government data, and the mechanisms that govern AI agents. Taking new engagements: hello@andrewfribush.com.

I write when a system teaches me something. Get new posts by email — no tracking, one-click unsubscribe.