Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(replay-vision): stop classifier freeform tags duplicating fixed vocabulary (#63650)

Kim Svatos Dugand66978326c94
diff --git a/products/replay_vision/backend/temporal/scanners/classifier.py b/products/replay_vision/backend/temporal/scanners/classifier.py
index 4db31227522b..dc71b52e87c9 100644
--- a/products/replay_vision/backend/temporal/scanners/classifier.py
+++ b/products/replay_vision/backend/temporal/scanners/classifier.py
@@ -70,8 +70,9 @@ class ClassifierScanner(BaseScanner, frozen=True):
default_factory=list,
max_length=_MAX_FREEFORM_TAGS,
description=(
- f"Up to {_MAX_FREEFORM_TAGS} short lowercase phrases capturing aspects not covered by the "
- "fixed vocabulary. Skip when nothing meaningful applies."
+ f"Up to {_MAX_FREEFORM_TAGS} short lowercase snake_case identifiers, ONLY for concepts no "
+ "fixed-vocabulary tag covers. Never paraphrase or restate a fixed tag here. Skip when nothing "
+ "meaningful applies."
),
),
)
diff --git a/products/replay_vision/backend/temporal/scanners/prompts/classifier.jinja b/products/replay_vision/backend/temporal/scanners/prompts/classifier.jinja
index fc800d1fbc6c..9edbe6409b5e 100644
--- a/products/replay_vision/backend/temporal/scanners/prompts/classifier.jinja
+++ b/products/replay_vision/backend/temporal/scanners/prompts/classifier.jinja
@@ -4,6 +4,6 @@
Choose tags from this fixed vocabulary: [{{ vocabulary }}]. {% if multi_label %}Pick every tag that applies.{% else %}Pick exactly one tag.{% endif %} Use `reasoning` to justify your choice.
{% if allow_freeform_tags %}
-You may additionally emit up to {{ max_freeform_tags }} `tags_freeform` — short lowercase snake_case identifiers (e.g. `password_reset`, `slow_checkout`) capturing aspects not covered by the fixed vocabulary. Skip the field entirely when the fixed tags already say everything that matters.
+The fixed vocabulary above is authoritative — whenever a fixed tag fits, pick it. You may additionally emit up to {{ max_freeform_tags }} `tags_freeform` ONLY for a concept that no fixed tag covers, even loosely. Each is a short lowercase snake_case identifier (e.g. `password_reset`, `slow_checkout`). Never emit a freeform tag that restates, paraphrases, abbreviates, pluralizes, or is a synonym of a fixed tag — pick the fixed tag instead (e.g. if `create new scanner` is in the vocabulary, do not coin `new_scanner` or `made_new_scanner`). Use one canonical identifier per concept; do not emit multiple wordings of the same idea. Skip the field entirely when the fixed tags already say everything that matters.
{% endif %}
{{ cite_in('reasoning') }}{% endblock %}
diff --git a/products/replay_vision/backend/tests/test_scanners.py b/products/replay_vision/backend/tests/test_scanners.py
index b08e47a676f5..e283c7097ce8 100644
--- a/products/replay_vision/backend/tests/test_scanners.py
+++ b/products/replay_vision/backend/tests/test_scanners.py
@@ -363,6 +363,22 @@ class TestClassifierScanner:
assert "tags_freeform" in on.build_prompt(team_name="Acme", events=events)
assert "tags_freeform" not in off.build_prompt(team_name="Acme", events=events)
+ def test_freeform_prompt_block_discourages_paraphrasing_fixed_vocab(self) -> None:
+ scanner = scanner_from_db(
+ _build_replay_scanner(
+ scanner_type=ScannerType.CLASSIFIER,
+ scanner_config={"prompt": "x", "tags": ["create new scanner"], "allow_freeform_tags": True},
+ )
+ )
+ rendered = scanner.build_prompt(team_name="Acme", events=EventTable(columns=[], rows=[]))
+ # Fixed vocabulary is authoritative and the model is told not to paraphrase a fixed tag into freeform.
+ assert "authoritative" in rendered
+ assert "synonym" in rendered
+ assert "'create new scanner'" in rendered
+ # Examples and the skip instruction survive the rewrite.
+ assert "password_reset" in rendered
+ assert "Skip the field entirely" in rendered
+
def test_finalize_strips_overlap_with_fixed_vocab_case_insensitive(self) -> None:
scanner = scanner_from_db(
_build_replay_scanner(