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(aio): stop eval reports shipping dead backticked identifiers (#81501)

posthog[bot]403d6b1170a5
diff --git a/posthog/temporal/ai_observability/eval_reports/report_agent/prompts.py b/posthog/temporal/ai_observability/eval_reports/report_agent/prompts.py
index 1462e1b0766e..81202d42a119 100644
--- a/posthog/temporal/ai_observability/eval_reports/report_agent/prompts.py
+++ b/posthog/temporal/ai_observability/eval_reports/report_agent/prompts.py
@@ -35,6 +35,7 @@ You build the report incrementally by calling three output tools:
- Don't invent sections just to fill space. One or two sections is enough for a routine report.
- Don't speculate beyond the data. Every claim should be traceable to a tool result. State uncertainty clearly.
- Don't emit emoji or marketing language. Be technical and factual.
+- Don't wrap a run_id from `list_recent_report_runs` or `get_report_run` in backticks. Only a generation, trace, or session ID you cite becomes a link; a backticked run_id renders as dead text. Name a prior run by its period instead.
## Query tools available
diff --git a/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_tools.py b/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_tools.py
index 13dfc476eeae..d823d4ee7ee5 100644
--- a/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_tools.py
+++ b/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_tools.py
@@ -618,6 +618,39 @@ class TestAddSection(SimpleTestCase):
titles = [s.title for s in state["report"].sections]
self.assertEqual(titles, ["First", "Second", "Third"])
+ def test_rejects_section_backticking_an_uncited_uuid(self):
+ # A run_id from list_recent_report_runs is a canonical UUID but not citable,
+ # so backticking it would ship a dead identifier. The guard blocks it in-loop.
+ state = _state_with_empty_report()
+ run_id = "0195f0a1-2b3c-7d4e-8f90-1a2b3c4d5e6f"
+ result = _add_section_fn(state=state, title="Summary", content=f"Steady since run `{run_id}`.")
+ self.assertIn("Error", result)
+ self.assertIn(run_id, result)
+ self.assertEqual(state["report"].sections, [])
+
+ def test_allows_section_when_backticked_uuid_is_cited(self):
+ state = _state_with_empty_report()
+ state["report"].citations.append(Citation(generation_id=_VALID_GEN_ID, trace_id=_VALID_TRACE_ID))
+ result = _add_section_fn(state=state, title="Summary", content=f"See `{_VALID_GEN_ID}` for the regression.")
+ self.assertNotIn("Error", result)
+ self.assertEqual(len(state["report"].sections), 1)
+
+ @parameterized.expand(
+ [
+ ("different_casing", f"`{_VALID_GEN_ID.upper()}`"),
+ ("surrounding_spaces", f"` {_VALID_GEN_ID} `"),
+ ("multiple_backticks", f"``{_VALID_GEN_ID}``"),
+ ]
+ )
+ def test_rejects_cited_uuid_when_format_will_not_link(self, _name: str, formatted_id: str) -> None:
+ state = _state_with_empty_report()
+ state["report"].citations.append(Citation(generation_id=_VALID_GEN_ID, trace_id=_VALID_TRACE_ID))
+
+ result = _add_section_fn(state=state, title="Summary", content=f"See {formatted_id} for the regression.")
+
+ self.assertIn("Error", result)
+ self.assertEqual(state["report"].sections, [])
+
class TestAddCitation(SimpleTestCase):
def test_appends_citation(self):
diff --git a/posthog/temporal/ai_observability/eval_reports/report_agent/tools.py b/posthog/temporal/ai_observability/eval_reports/report_agent/tools.py
index 4ddef5e3a6d9..9d9b5eb2f156 100644
--- a/posthog/temporal/ai_observability/eval_reports/report_agent/tools.py
+++ b/posthog/temporal/ai_observability/eval_reports/report_agent/tools.py
@@ -65,6 +65,13 @@ logger = structlog.get_logger(__name__)
# so they use bounded validation and always flow through AST constants instead.
_UUID_RE = re.compile(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$")
+# Detect UUID-shaped inline-code variants broadly because only an exact cited ID
+# in one pair of backticks becomes a code-span link in every report renderer.
+_BACKTICKED_UUID_RE = re.compile(
+ r"`+\s*([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\s*`+",
+ re.IGNORECASE,
+)
+
_TARGET_ID_EXPRESSION = "coalesce(nullIf(properties.$ai_target_id, ''), properties.$ai_target_event_id)"
_MAX_OPAQUE_ID_LENGTH = 255
_MAX_TRACE_SAMPLE_IDS = 10
@@ -1463,6 +1470,19 @@ def set_title(
return f"Title set: {clean!r}"
+def _unlinked_backticked_uuids(content: str, citations: list[Citation]) -> list[str]:
+ """Return backticked canonical UUIDs that will not be links in every report renderer."""
+ cited_ids = {citation.cited_id() for citation in citations}
+ unlinked: list[str] = []
+ for match in _BACKTICKED_UUID_RE.finditer(content):
+ uuid_value = match.group(1)
+ has_exact_citation = uuid_value in cited_ids
+ uses_linkable_wrapper = match.group(0) == f"`{uuid_value}`"
+ if not (has_exact_citation and uses_linkable_wrapper) and uuid_value not in unlinked:
+ unlinked.append(uuid_value)
+ return unlinked
+
+
@tool
def add_section(
state: Annotated[dict, InjectedState],
@@ -1499,6 +1519,14 @@ def add_section(
f"Error: maximum of {MAX_REPORT_SECTIONS} sections reached. "
"Merge your content into existing sections rather than fragmenting further."
)
+ unlinked = _unlinked_backticked_uuids(clean_content, state["report"].citations)
+ if unlinked:
+ preview = ", ".join(f"`{uuid_value}`" for uuid_value in unlinked[:3])
+ return (
+ f"Error: the following backticked IDs will not render as citation links: {preview}. "
+ "Cite each generation, trace, or session with add_citation, then use one pair of backticks around the exact cited ID. "
+ "Run IDs from list_recent_report_runs cannot be cited. Name a prior run by its period and remove the backticks."
+ )
state["report"].sections.append(ReportSection(title=clean_title, content=clean_content))
return f"Section {len(state['report'].sections)}/{MAX_REPORT_SECTIONS} added: {clean_title!r} ({len(clean_content)} chars)"