Sub topic 4
Mentions: detecting a brand in an answer
This chapter covers how a tracking tool decides whether a brand appears in an AI answer. It assumes you know what a prompt set is and how a run is recorded (earlier chapters), and that you can read short Python. Citations, share of voice, and sentiment get their own chapters. Here we deal only with the first step: deciding, for each answer, whether a brand was mentioned.
What counts as a mention
A mention is an occurrence of the brand, or one of its known names, in the text of the answer. Mentions are about the answer body. A link to your domain in the source list is a citation, and a tool should record it in a separate field.
The two can disagree:
- An answer can name your brand without citing your site. The model learned about you from other pages.
- An answer can cite your site without naming you. The model used your page as a source but wrote a generic sentence.
If a tool merges these into one "visibility" number, you can't tell which kind of presence you have. Keep mention detection on the answer text only.
Three decisions define a mention metric, and a tool should state each one:
- Presence or count. Most reports use presence: was the brand in this answer, yes or no. Counting every occurrence rewards long answers that repeat a name.
- Valence. A mention is counted whether it is praise or a warning. "Avoid Acme, it is slow" is a mention. Sentiment is a separate attribute, covered in a later chapter.
- Unit. The unit is usually one answer to one prompt in one run. Mention rate is then the share of runs where the brand was present.
The detection pipeline
Detection is a small pipeline. Each stage can add errors, so it helps to keep them separate.
Keeping the raw text matters. When you later improve your alias list, you can re-run detection on stored answers instead of paying to collect them again.
Aliases: the list of names for one entity
An entity is the real-world brand. Aliases are the strings that refer to it. A brand called "DeltaDesk" may appear as:
- "DeltaDesk" and "Delta Desk" (spacing varies)
- "DeltaDesk CRM" (a product name)
- "Delta Desk Inc." (the legal name)
- "@deltadesk" or "deltadesk.com" in running text
- A common misspelling the engine produces
Build the list by reading real answers, not by guessing. Run your prompt set once, search the answers for fragments of your name, and add what you find. Review the list again when you launch a product or rebrand.
Decide how product names roll up. If "DeltaDesk Mail" is a product of the DeltaDesk company, you can count it toward the parent brand, track it as its own entity, or both. Pick one rule and apply it to competitors too, or your share-of-voice comparison will be skewed.
Matching with boundaries
Plain substring search is the most common beginner mistake. Searching for "acme" finds it inside "Acmeville", and searching for "Apex" finds it inside "Apex Legends" when you meant the software. Boundaries fix the first problem. Exclusions, shown later, handle the second.
The usual tool is the regular expression word boundary \b. It works for aliases that start and end with letters or digits. It breaks for aliases that start or end with a symbol, such as "C++" or ".NET". A more general pattern uses lookarounds: the alias must not be preceded or followed by a word character.
Some behaviours to expect from boundary matching:
- "Acme's" matches "Acme", because the apostrophe is not a word character.
- "Acme-based" also matches, because the hyphen is not a word character. That is usually what you want.
- "Acmeville" does not match "Acme".
- "ACME" and "acme" match when you ignore case.
Ambiguous names
If your brand name is a common word (Apple, Mercury, Notion, Slack), case-insensitive matching produces false positives. You have three tools:
- Case-sensitive aliases. Require the capitalised form "Mercury", so the lowercase word "mercury" in a chemistry answer is ignored. This helps with common nouns but not with sentence-initial capitals.
- Longer aliases. Use "Mercury CRM" in place of bare "Mercury".
- Exclusion phrases. Blank out known non-brand phrases such as "Mercury retrograde" before matching.
Blank the excluded text with spaces of the same length instead of deleting it. Then the character offsets of later matches still point to the right place in the original answer.
A working detector
This code implements the pipeline: exclusions, case-insensitive and case-sensitive aliases, boundary matching, and span merging. It runs as shown.
import re
from dataclasses import dataclass, field
@dataclass
class Brand:
name: str
aliases: list # matched ignoring case
exact_case: list = field(default_factory=list) # matched case-sensitively
exclude: list = field(default_factory=list) # phrases that are not the brand
def _pattern(term, ignore_case):
flags = re.IGNORECASE if ignore_case else 0
return re.compile(rf"(?<!\w){re.escape(term)}(?!\w)", flags)
def merge(spans):
merged = []
for start, end in sorted(spans):
if merged and start < merged[-1][1]:
merged[-1] = (merged[-1][0], max(merged[-1][1], end))
else:
merged.append((start, end))
return merged
def find_mentions(answer, brand):
text = answer
for phrase in brand.exclude:
text = _pattern(phrase, True).sub(lambda m: " " * len(m.group()), text)
spans = []
for alias in brand.aliases:
spans += [m.span() for m in _pattern(alias, True).finditer(text)]
for alias in brand.exact_case:
spans += [m.span() for m in _pattern(alias, False).finditer(text)]
return merge(spans)
brands = [
Brand("Mercury", aliases=["Mercury CRM"], exact_case=["Mercury"],
exclude=["Mercury retrograde"]),
Brand("DeltaDesk", aliases=["DeltaDesk", "Delta Desk"]),
]
answers = [
"Mercury retrograde is overrated. For small teams, try Mercury CRM or DeltaDesk.",
"The planet shines; Mercury retrograde starts Friday.",
"Delta Desk's pricing is simple.",
"Avoid DeltaDesk; it is slow.",
]
for answer in answers:
print({b.name: bool(find_mentions(answer, b)) for b in brands})The output is:
{'Mercury': True, 'DeltaDesk': True}
{'Mercury': False, 'DeltaDesk': False}
{'Mercury': False, 'DeltaDesk': True}
{'Mercury': False, 'DeltaDesk': True}In the first answer, "Mercury CRM" matches both the alias and the case-sensitive "Mercury". Merging joins them into one span, so the brand is counted once at that location. The fourth answer is a negative mention, and it still counts as a mention.
Common failure modes
| Problem | Example | Type of error | Typical fix |
|---|---|---|---|
| Substring match | "Acme" inside "Acmeville" | False positive | Boundary matching |
| Common-word brand | "mercury" in a chemistry answer | False positive | Case-sensitive or longer alias |
| Non-brand phrase | "Mercury retrograde" | False positive | Exclusion phrase |
| Spacing or hyphen variant | "Delta-Desk" | False negative | Add alias |
| Product name only | "DeltaDesk Mail" | False negative or double count | Roll-up rule |
| Misspelling | "Deltadesk" with a typo | False negative | Add alias from observed answers |
| Name in a link only | `deltadesk.com/pricing` in a source list | Not a mention | Record as citation |
| Paraphrase | "the CRM from the Delta company" | False negative | LLM-based classifier, or accept the gap |
Regex versus a language-model classifier
Some tools ask a second model: "Does this answer recommend or name DeltaDesk?" This handles paraphrases and ambiguous names better, since the classifier can tell the planet from the software. The costs are real:
- The classifier is itself non-deterministic. Run it twice and you may get different labels for the same text.
- It adds cost per answer.
- It is harder to audit. You can read a regex and see why it matched.
- Its definition of "mentioned" can drift with the prompt or model version.
A practical design is to use rules as the default, send only ambiguous cases to a model, and store both labels so you can see where they disagree. When you compare tools, ask which method each one uses (see the later chapter on tool evaluation).
Measuring detector quality
Do not trust a detector because it looks reasonable. Label a sample by hand: pick 50 to 100 stored answers, mark whether each truly mentions the brand, and compare with the detector's output. Then compute two numbers:
- Precision: of the answers the detector flagged, the share that truly mention the brand. Low precision means false positives inflate your rate.
- Recall: of the answers that truly mention the brand, the share the detector found. Low recall means false negatives hide real presence.
def precision_recall(labels):
# labels: list of (predicted, truth) booleans
tp = sum(1 for p, t in labels if p and t)
fp = sum(1 for p, t in labels if p and not t)
fn = sum(1 for p, t in labels if not p and t)
precision = tp / (tp + fp) if tp + fp else 0.0
recall = tp / (tp + fn) if tp + fn else 0.0
return precision, recall
labels = [(True, True)] * 18 + [(True, False)] * 2 + [(False, True)] * 4 + [(False, False)] * 16
precision, recall = precision_recall(labels)
print(f"precision {precision:.2f}, recall {recall:.2f}")This prints precision 0.90, recall 0.82. Here the detector misses about one real mention in five. Read the false negatives first, because each one usually points to a missing alias.
Measure per brand. A detector can be excellent for "DeltaDesk" and poor for "Mercury". If competitors are scored with weaker detection than your own brand, your share of voice will be biased in a direction you can't see from the final number.
Practical rules
- Store the raw answer, the matched spans, and the alias that matched. You need them to debug.
- Version your alias list. When it changes, re-run detection on stored answers before comparing periods, or a rate change may come from the list and not from the engine.
- Apply the same matching rules to every brand in the comparison.
- Report the unit with the number: "mentioned in 12 of 40 runs", not just "30%".
Exercises
Exercise
Your brand is "Notion Pro". A tracking tool searches answers for the substring "notion" ignoring case, and reports a 60% mention rate. Name two kinds of false positive this can produce, and give one fix for each.
Show answer
First, the common word "notion" in ordinary prose (for example "a notion of fairness") matches. Fix it with a longer alias such as "Notion Pro", or a case-sensitive alias plus context rules. Second, substrings inside longer words such as "notional" or "emotion" can match, since "emotion" contains "notion". Fix it with boundary matching, such as (?<!\w)notion(?!\w). Hand-labelling a sample and computing precision would show how large the problem is.
Exercise
A hand-labelled sample of 50 answers has 20 that truly mention your brand. The detector flags 16 answers, and 15 of them are correct. Compute precision and recall, and say which kind of error is the bigger problem.
Show answer
True positives are 15, false positives are 1, false negatives are 20 - 15 = 5. Precision is 15/16 = 0.94. Recall is 15/20 = 0.75. Recall is the bigger problem: the detector misses a quarter of real mentions, so the reported mention rate is too low. Reading the five missed answers should reveal aliases, spellings, or paraphrases to add.