Storing verified facts is half the work. The other half is making sure every generator reads them the same way, and that when an article says something wrong about a brand, there is a record of exactly what the generator was given. Before this, each generator assembled its own picture of the brand, and one of them was missing half of it.
The problem
The tenth failure in the onboarding review was quiet. Card news generated for a brand lacked the brand’s identity and products, although the customer had entered them. The card news generator read the brand through a different code path from the blog writer, and that path did not include the fields the onboarding flow filled in.
Nothing errored. The output was simply blander than it should have been, and nobody could say why without reading both paths side by side. Two generators with two readers will drift, and a third generator makes it three.
There was a second gap. When a generated sentence looked wrong, the question “what did the model see?” had no answer. The context was built in memory, used once and thrown away.
One function

load_brand_context is the only way a generator gets brand knowledge. It reads the brand document once, so everything it returns belongs to one revision. It loads the glossary’s forbidden terms and the brand’s active chunks, and returns a context object with three parts: the fields that may be used, the evidence chunks, and a trace.
The blog writer calls it directly. Card news and banners reach it through a facts port that the brand-identity package exposes, and that port is wired to the same function. The failure above was fixed by pointing the port at the loader. There is now one reader with several callers.
Which fields may be used
Not every stored field is safe to write from. A value the model observed on the site and nobody has confirmed is a guess with a citation.
def usable(brand: Brand, field_name: str) -> bool:
meta = brand.field_meta.get(field_name)
return (meta is None or meta.origin == "user" or meta.review == "confirmed"
or meta.basis == "explicit")
| The field is | Used in generation |
|---|---|
| written or adopted by a person | yes |
| extracted and confirmed by a person | yes |
extracted with basis explicit: features, proof points, products, each with a verified quote | yes |
extracted with basis observed, not yet confirmed | no: withheld |
| without metadata, from before the pipeline | yes, treated as a person’s |
A withheld field is blanked in the copy the generator receives and its name is listed in the trace. The stored brand is not changed. The effect is that confirming a field in the dashboard is what releases it to the generators, and the trace of an article written before the confirmation shows the field was held back.
Which evidence goes in
RETRIEVAL_CONFIG: dict = {
"name": "rc-0",
"method": "field_evidence_then_term_overlap",
"top_k": 6,
"max_chars": 6000,
"status": "active",
}
RETRIEVAL_CONFIG_VERSION = "rc-0:" + hashlib.sha256(
json.dumps(RETRIEVAL_CONFIG, sort_keys=True).encode()).hexdigest()[:8]
Selection has two steps and no model.
- Chunks that fields cite come first. Every usable field with a verified quote points at a chunk. Those chunks are the passages the brand’s own facts rest on.
- The rest are ranked by term overlap with the task. The task’s topic and query are reduced to content terms, and each remaining chunk is scored by how many of those terms appear in it. Chunks that score zero are left out. Ties keep their original order.
The list is cut at six chunks, and stops early if adding the next chunk would pass 6,000 characters.
This is a modest retriever and I do not claim otherwise. It has one property I wanted before anything cleverer: it is deterministic. The same brand revision and the same task give the same chunks in the same order.
The version string is the name plus a hash of the whole config. Change the top-k from 6 to 8 and the version changes, without anyone remembering to bump it. Any output produced under the new config says so in its trace, so a shift in what the generators write can be lined up with the change that caused it.
What is recorded
| Trace field | What it holds |
|---|---|
workspace_id, brand_id | whose context this was |
brand_revision | the revision of the brand document that was read |
chunk_ids | the evidence chunks placed in the context |
retrieval_config_version | for example rc-0: followed by eight hex characters |
context_hash | a hash of the facts handed over and the chunk ids |
withheld | the fields that were held back as unconfirmed |
The trace is stored with the output. For an article it is in the article’s generation record. For card news it is on the document. For a banner it is on the render.
With it, a wrong sentence can be investigated in a fixed order. Read the trace. Look up the chunks by id, which still exist even if they have been retired since. Check whether the claim is in them. If it is, the page said it and the question is for the brand. If it is not, the model added it, and the context hash says whether two outputs with the same problem were given the same input.
The evidence chunks have a second use. The writer has a fidelity check on the numbers in a draft, and the numbers that appear in the evidence chunks are added to the set a draft is allowed to contain.
Failure modes
| What goes wrong | What happens | Regression test |
|---|---|---|
| A channel reads the brand through its own path and misses fields | all channels read through the loader | test_f10_cardnews_snapshot_carries_onboarding_knowledge |
| The blog prompt and the card news snapshot disagree | they carry the same knowledge, and the trace is recorded | test_blog_writer_prompt_carries_the_same_knowledge_and_records_trace |
| An unconfirmed direction field leaks into an article | it is withheld and listed | test_comparison_article_prompt_weaves_confirmed_direction_into_target_prompts |
| A claim with no verified quote reaches a prompt | it was dropped at extraction, so it is not in the context | covered in test_brand_context.py |
Limits I know about
The trace is per output, not per sentence. It records which chunks were in the context. It does not say which sentence drew on which chunk, or whether a sentence drew on any. Judging each claim against a chunk is specified as a later stage and not built. Today the trace narrows the search for a wrong sentence to at most six chunks.
Two generators do not save a trace yet. Detail pages and slides do not store what they were given.
Channels send no query. The facts port builds its task without a topic, so card news and banners receive only the chunks that fields cite and none chosen by term overlap. For short copy that is acceptable. It means the second selection step is exercised only by the blog writer.
Term overlap is a substring count. It does not know that two words mean the same thing, and it favours long chunks that mention many terms once. Its replacement is the subject of the next article, and select_evidence is the one function that replacement has to change.
Nothing tests the ranking directly. The tests assert that the right knowledge reaches the prompt and that the version prefix is recorded. None asserts the order of chunks for a given query.
