Prompt provenance and stated counts: which wording wrote a draft, and whether its numbers are right
Two guarantees on AI-drafted text, both built so a reviewer can rely on what they sign:
- Provenance. A draft records the name and version of the prompt that wrote it, so an approval recorded against a token id names the wording that was approved.
- Stated counts. The shift handoff is given its counts by code, and a draft that states a different count is rejected before it reaches anyone.
1. What is recorded
Two keys, prompt_name and prompt_version, written by engine/narrative_drafting.py
(PROMPT_NAME_KEY, PROMPT_VERSION_KEY). They hold the name and the version from the prompt asset's
front matter, for example shift_handoff_summary_drafting and 0.7.0.
| Draft | In its stored content | In its Activity Log entry's reference ids |
|---|---|---|
| Shift handoff summary | yes | yes |
| Case summary | yes | yes |
| Playbook draft | yes (the drafting prompt) | yes |
| Order narrative | not stored (it is returned, not queued) | yes |
| Time-ranged activity narrative | in the returned result | yes |
| Point-of-use SOP answer | not stored | yes, for an answer a model wrote |
The Activity Log entry for a run keeps its existing reference ids (pending_signoff_id,
precedent_retrieval, order_id, the retrieved chunks, and so on); the two keys sit beside them.
What is never recorded
- The prompt's wording. Only the name and version are stored or logged. The wording is a licensed asset; a record that held it would copy that asset into every sign-off record and log entry. To see the wording a version had, read that version of the asset.
- A prompt for text no prompt wrote. The deterministic fallback summaries (unlicensed, inference disabled, the degraded fallback, and the fallback below for a rejected count), an inference-disabled narrative, and a refusal ("not enough information") carry neither key. Their absence is how you tell them from a model-written draft.
- The classification prompt. A playbook draft names the drafting prompt, which wrote the text a reviewer reads. The document type the classifier chose is shown beside it.
- Four drafting calls do not record their prompt: the abnormal-status reasoning, the inventory-shortage explanation, the instruction-claim drafting and the SOP lookup's merge step make a model call without naming their prompt in their own record. A test lists them, so taking one on is a deliberate change.
A record stored before these keys existed has neither, reads back unchanged, and nothing requires them.
2. Reading it
On the review page, a draft that names a prompt shows a Wording line beside it, for example
shift_handoff_summary_drafting 0.7.0. A record with no prompt shows no line. Approving still
records the reviewer's token id as before.
From the Activity Log, find every run a wording wrote by narrowing a query to the key:
from engine.activity_log import ActivityLog
log = ActivityLog()
entries = log.query(reference_id="shift_handoff_summary_drafting", reference_ids_key="prompt_name")
old_wording = [e for e in entries if e.reference_ids.get("prompt_version") == "0.6.0"]
An edited draft keeps its top-level keys when a reviewer edits it, so the successor still names
the prompt that wrote the original text. The text a reviewer approved after editing is theirs; the
keys say where it started. An edited successor is told apart by its predecessor_id (the review
page's Replaces line), so to audit only what a wording itself wrote, leave out records that have
one.
Bump the version when the wording changes. The record and the cache both rely on the name and version identifying the wording. A prompt edited without a new version is indistinguishable from the old one.
The order-narrative cache
The order narrative's cache key includes the prompt's name and version, so a prompt revision needs no
cache flush and a cache hit names the prompt that wrote the cached text. See
docs/operations/order-narrative-result-caching.md.
3. Stated counts
The shift handoff's payload carries a counts block of the true totals for the window:
"counts": {
"activity_log_entries": 12,
"reconciliation_events": 6,
"pending_cases_awaiting_sign_off": 0
}
They are computed from the same lists the fallback summary prints and the stored record keeps
(activity_count, reconciliation_count, pending_case_count), so the three can never differ. The
lists in the payload show only the most recent entries of a busy shift, which is why a model must not
count them; the licensed prompt asset (version 0.7.0 and later) tells it to use the block exactly.
The check
engine/stated_counts.py reads a draft and rejects it, through the validator hook on
InferenceClient.call, when it states a count for one of those three nouns and never states the right
one. The call is then retried at the model's usual retry schedule.
- Read: a number directly before the noun, as digits (
3,1,200) or as a number word from zero to twenty (three), foractivity log entries,reconciliation eventsandcases awaiting sign-off(alsopending cases). - Accepted: a draft that names no count, a count it cannot parse (
a few,twenty-one), a range (between 2 and 4), a number that picks out part of the whole (the last 5,at least 2,one of the events), a count the draft narrows (the 20 activity log entries shown,1 reconciliation event unresolved), a number beside a different noun (2 reconciliation discrepancies), and a draft that states the right count anywhere even if it also states another ("three events, one unresolved"). - Rejected:
two reconciliation eventswhere the log counted three.
If the retries run out because of a count, the draft is not raised as an error: the structured
facts stand in, with a line saying a drafted narrative was withheld because its counts did not match
the log's. It is an ordinary pending draft, signed off like any other, with no prompt keys, since no prompt
wrote it, and no precedents, since none grounds it. Its precedent_retrieval still says what
retrieval did: unavailable (with its failure class) for an outage and none_found for a search that
found nothing, so the health of retrieval stays visible on these records. A retrieval that did find
chunks is recorded as not_attempted, because used would claim precedents the text does not have.
The withheld record and its Activity Log entry carry draft_withheld set to stated_count_mismatch,
and no other record does. That is how an operator counts them, since the entry's outcome is still
drafted and the failure policy sees a success:
withheld = log.query(reference_id="stated_count_mismatch", reference_ids_key="draft_withheld")
A call that fails for any other reason (an outage, a refusal) still raises, and the failure policy handles it.
The rejection reason names the counts and never the draft's text.
Pitfalls
- A new prompt asset version is a new release action. The engine pins the shift-handoff asset's version, so a site must update the licensed asset to the version a release names. With the old asset the Node refuses to start and the error names both versions (the asset's and the one expected). With no asset file at all it takes the unlicensed fallback, as before.
- The check is narrow on purpose. It catches the common slip, a wrong number beside the counted noun. It does not catch a wrong count in a form it cannot read, and it is not a check that the rest of the prose is true.
- A true statement about part of the whole can be rejected. The check cannot tell "two
reconciliation events were reviewed" (true, a subset) from "two reconciliation events" (the slip it
exists to catch): both are a number directly before the noun. It skips the phrasings it can name
(
the last 5,2 events unresolved,the 20 entries shown), accepts a draft that also states the right total anywhere, and the prompt tells the model to state the totals, but a draft that states only a partial count in other words is retried and then withheld. That costs a fact listing, not a wrong number. Ifdraft_withheldrecords pile up, read a few of the model's drafts before changing the check. - The fallback is not a failure. A reviewer who sees the withheld-narrative line is looking at the correct counts. If it appears often, the model is stating counts the log does not hold; check the model and the prompt version.
Release: v0.11.0