: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(aio): ground eval report caveats in captured input (#124798)
Bernat Torres2a30aa2fff2a
diff --git a/docs/internal/ai-observability-judge-inputs.md b/docs/internal/ai-observability-judge-inputs.mdindex 1fb1a2fb9ad7..05fe43ebe3ba 100644--- a/docs/internal/ai-observability-judge-inputs.md+++ b/docs/internal/ai-observability-judge-inputs.md@@ -287,8 +287,12 @@ Large results reduce the number of examples returned; each returned example keepThe tools indicate when examples are omitted, and aggregate counts and pass rates still cover the full period.The report agent's `sample_generation_details` tool keeps the beginning and end of input and input-state previews within 500 characters, with an elision marker.+Each sample includes `input_length`, the stored input's character count before shortening the preview.Both sampled and full generation details include input, output, cache-read, and cache-creation token counts.-The agent must inspect full generation details before claiming captured input is truncated or instrumentation is broken. Previews and low input token counts alone are insufficient evidence.+The agent must inspect full generation details before claiming captured input is truncated or instrumentation is broken, and report a limitation only when those details confirm it.+Shortened previews and low input token counts alongside high cache-read or cache-creation token counts are expected and alone do not justify an auditability caveat.+A trace can contain many generations by design; use generation IDs to distinguish individual calls.+The agent must recheck these caveats from prior reports against current full generation details and omit caveats that the data does not support.## Browser compatibilitydiff --git a/posthog/temporal/ai_observability/eval_reports/report_agent/prompts.py b/posthog/temporal/ai_observability/eval_reports/report_agent/prompts.pyindex b1b2c729f0cd..77d019953c92 100644--- a/posthog/temporal/ai_observability/eval_reports/report_agent/prompts.py+++ b/posthog/temporal/ai_observability/eval_reports/report_agent/prompts.py@@ -273,7 +273,8 @@ If a session cannot be resolved, try another example. If none resolve, report th)detail_tools_section = ("- **`sample_generation_details(generation_ids)`**: 500-character head-and-tail input previews, "- "output previews, model, token counts including cache usage, and trace ID. Call this before citing.\n"+ "full stored input length (`input_length`, in characters), output previews, model, token counts "+ "including cache usage, and trace ID. Call this before citing.\n""- **`get_generation_detail(generation_id)`**: complete data for one generation and its evaluation ""results.\n""- **`get_generation_text_repr(generation_id)`**: canonical rendering for a generation."@@ -287,7 +288,13 @@ If a session cannot be resolved, try another example. If none resolve, report thIf a generation cannot be resolved, try another example. If none resolve, report the data-quality limitation.-Sample previews omit content. You must call `get_generation_detail` before claiming that captured input is truncated or instrumentation is broken. Low `input_tokens` alone is not evidence of missing input: inspect `cache_read_input_tokens` and `cache_creation_input_tokens` as well as the complete input."""+Sample previews deliberately omit content. `input_length` counts the stored input's characters before shortening the preview. A message or marker absent from a preview is not evidence of missing captured input. You must call `get_generation_detail` before claiming that captured input is truncated or instrumentation is broken, and only report a limitation if the full detail confirms it.++Prompt caching is normal. Low `input_tokens` alongside high `cache_read_input_tokens` or `cache_creation_input_tokens` does not indicate missing input or an auditability risk. Do not add caveats or recommendations based on this alone.++A trace can contain many generations by design. Shared `trace_id` values do not imply duplicate or misattributed generations. Use `generation_id` to distinguish individual calls.++Recheck any such caveat from a prior report against current full generation details. If those details show no limitation, omit the caveat instead of repeating it as a standing risk."""detail_step = "Call `sample_generation_details(...)` on 3-5 useful examples."else:raise ValueError(f"Unsupported evaluation target: {evaluation_target}")diff --git a/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_graph.py b/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_graph.pyindex a409ee505c00..bf2beb7127e2 100644--- a/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_graph.py+++ b/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_graph.py@@ -131,6 +131,10 @@ class TestSystemPromptFormat(SimpleTestCase):"must call `get_generation_detail` before claiming","cache_read_input_tokens","cache_creation_input_tokens",+ "input_length",+ "Prompt caching is normal",+ "A trace can contain many generations",+ "Recheck any such caveat from a prior report",],["sample_trace_details", "sample_session_details"],),diff --git a/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_tools_ai_events_routing.py b/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_tools_ai_events_routing.pyindex dd72bf3e0a57..b57645d4bfef 100644--- a/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_tools_ai_events_routing.py+++ b/posthog/temporal/ai_observability/eval_reports/report_agent/test/test_tools_ai_events_routing.py@@ -55,9 +55,11 @@ def _resolver_response(rows: list[list]) -> MagicMock:class TestSampleGenerationDetailsRoutesThroughResolver(BaseTest):@parameterized.expand([+ ("missing", None, None, None),("short", [{"role": "user", "content": "hi"}], None, None),("at_limit", "x" * 500, 0, 0),("long", "BEGIN_INPUT " + "x" * 800 + " END_INPUT", 1000, 50),+ ("unicode", "🦔" * 600, 1000, 50),])@patch("posthog.hogql_queries.ai.ai_table_resolver.query_ai_events")@@ -65,7 +67,7 @@ class TestSampleGenerationDetailsRoutesThroughResolver(BaseTest):def test_routes_through_resolver_against_ai_events(self,_name: str,- input_value: str | list[dict[str, str]],+ input_value: str | list[dict[str, str]] | None,cache_read_tokens: int | None,cache_creation_tokens: int | None,_mock_lookup: MagicMock,@@ -99,8 +101,12 @@ class TestSampleGenerationDetailsRoutesThroughResolver(BaseTest):# Returns rendered JSON with input/output previews from heavy columns.assert resultgeneration = json.loads(result)[0]- input_text = str(input_value)- for preview in (generation["input_preview"], generation["input_state_preview"]):+ input_text = str(input_value) if input_value else ""+ assert generation["input_length"] == len(input_text)+ previews = [generation["input_preview"]]+ if input_value:+ previews.append(generation["input_state_preview"])+ for preview in previews:if len(input_text) <= 500:assert preview == input_textelse:diff --git a/posthog/temporal/ai_observability/eval_reports/report_agent/tools.py b/posthog/temporal/ai_observability/eval_reports/report_agent/tools.pyindex 7a0044e6469a..0fb27b6c7cf3 100644--- a/posthog/temporal/ai_observability/eval_reports/report_agent/tools.py+++ b/posthog/temporal/ai_observability/eval_reports/report_agent/tools.py@@ -884,8 +884,9 @@ def sample_generation_details("""Get $ai_generation previews and token usage for specific generations.Input previews keep the head and tail within 500 characters. Output previews- keep the first 500 characters. Returns model, token counts including cache- usage, and trace_id for verification before citing in the report.+ keep the first 500 characters. Returns the stored input's full character count+ as input_length, model, token counts including cache usage, and trace_id for+ verification before citing in the report.**Always call this before add_citation** so you have the trace_id to pass in.Args:@@ -964,12 +965,13 @@ def sample_generation_details(result = []for row in rows:- input_text = truncate_to_head_tail(str(row[2]), max_chars=500, head_chars=250) if row[2] else ""+ input_text = str(row[2]) if row[2] else ""output_text = str(row[3])[:500] if row[3] else ""entry: dict = {"generation_id": str(row[0]) if row[0] else "","model": str(row[1]) if row[1] else "",- "input_preview": input_text,+ "input_preview": truncate_to_head_tail(input_text, max_chars=500, head_chars=250),+ "input_length": len(input_text),"output_preview": output_text,"input_tokens": row[4],"output_tokens": row[5],