ai-powered-conversational-intelligence

PROMPT 46 — AI EVALUATION BENCHMARKING

Role

Act as a Principal AI Architect, Enterprise Data Platform Architect and Senior Product Engineer.

Mission

Build a first-class evaluation platform covering SQL correctness, semantic mapping, intent, planning, groundedness, calculations, anomaly/root cause, forecasting, recommendations, security and tenant isolation. Inspect existing golden questions and feedback. Version datasets and model/prompt/agent versions; track quality, latency and cost. Support deterministic assertions and human review. Add release gates for critical regressions and benchmark comparisons.

Mandatory workflow

INSPECT → PLAN → IMPLEMENT → TEST → REVIEW → FIX → DOCUMENT → REPORT

Mandatory controls

§0. Concurrent-work note

This prompt was executed in the same shared working tree as a separate, concurrent session’s own “Prompt 45” work (45_PROMPT_AGENT_REGISTRY_CONTRACT.md – an AI Prompt & Agent Registry layered on top of Prompt 44’s governance_center/ package, touching api/governance.py, api/governance_schemas.py, CLAUDE.md, docs/API.md, tests/security/README.md, tests/test_api_governance.py, plus its own new governance_center/{artifacts,inventory, safety,validation}.py and test files). Per the user’s own standing direction from the prior session’s identical collision (“leave it alone, commit mine separately”), none of those files or modules were read for anything beyond the two shared files this prompt’s own work genuinely needed to touch (identity/models.py, identity/rbac.py, api/main.py, eval/component_benchmark/runner.py, eval/baselines/component_benchmark_latest.json, tests/test_eval_component_benchmark.py) – every one of those five shared files was confirmed, by direct git diff, to carry only this prompt’s own additions with zero overlap from the concurrent session at the time of inspection. CLAUDE.md is the one file both sessions needed to append a new section to at the same location (end of the running “Key design decisions” list); this prompt’s own section was added immediately after the concurrent session’s already-present (but still uncommitted) Prompt 45 section, in strict numeric order, rather than fighting over which session “owns” that insertion point.

§1. INSPECT – what already existed

§2. PLAN

  1. Close the five named-but-uncovered eval/component_benchmark/ domains with the smallest honest scope: groundedness, calculations, anomaly/root cause, forecasting, and intent – each wrapping a real, already-tested production function directly, zero I/O, mirroring cases_semantic.py/cases_analytics.py’s own established shape exactly. “SQL correctness”/”security”/”tenant isolation” (the mission’s other three named domains) are deliberately not added as a sixth/seventh/eighth zero-I/O dataset here – each already has its own real, much larger evaluation harness that genuinely needs live infrastructure (SQL/security) or is already a CI-enforced pytest suite (tenant isolation); building a parallel always-passing stub for any of the three would misrepresent coverage, not add it.
  2. Build a new top-level package, eval_platform/, that combines results from every harness (reused, never recomputed) into one release-gate verdict, and a new persistence layer (identity.models.EvaluationRun/EvaluationCaseReview + identity/repositories/eval_platform.py) for the mission’s own “version datasets… track quality, latency and cost… support deterministic assertions and human review” requirements.
  3. New RBAC (Permission.EVAL_MANAGE/EVAL_REVIEW, the identical two-tier operational-vs-domain-judgment split every prior *_MANAGE/*_REVIEW pair in this codebase already establishes) and a new REST surface, api/eval_platform.py, mirroring api/governance.py/api/semantic_catalog.py’s own authorization/anti-enumeration discipline exactly.
  4. No Settings.enable_* feature flag – the identical reasoning api/governance.py’s own docstring already gives for an administrative/compliance surface gated purely by RBAC.

§3. IMPLEMENT

§3.1 Five new component-benchmark domains (eval/component_benchmark/)

All five were verified via direct scratch-script execution against the real production functions before being wired into the harness or committed to any test file – this caught four real field-name/logic mistakes before they ever reached a committed file: GrowthPoint.percent_change does not exist (the real field is change_percent_from_previous); RankingEntry.share_of_total_percent does not exist (the real field is share_percent); PercentileStat has a direct .p50 float attribute, not a .values dict; and ContributorStat.dimension_value does not exist (the real field is .label). A sixth, purely logical mistake was also caught and fixed before committing: an initial “no single dimension explains a uniform small change” root-cause test applied the same absolute change to only 3 regions, which legitimately gives each one an equal, non-trivial ~33% share of the total change – clearing the default 10% contribution floor for all three. Redesigned to use 20 regions each contributing an equal, genuinely small (~5%) share, which correctly produces zero contributors.

eval/component_benchmark/runner.py’s _DOMAIN_MODULES now lists 9 domains (up from 4); eval/baselines/component_benchmark_latest.json was regenerated via scripts/run_component_benchmark.py --save-baseline to include all 62 cases (up from 28); tests/test_eval_component_benchmark.py’s own _ALL_DOMAIN_MODULES dict was updated to match exactly (its own TestCommittedBaselineIsInSync test would otherwise fail against the updated runner).

§3.2 eval_platform/ – the cross-harness vocabulary and release gate

§3.3 Persistence (identity/models.py + identity/repositories/eval_platform.py)

§3.4 RBAC (identity/rbac.py)

Permission.EVAL_REVIEW (analyst tier – submitting a human review verdict is domain judgment, the identical reasoning every other *_REVIEW permission in this file already establishes) and Permission.EVAL_MANAGE (admin tier – recording a run and computing a release-gate verdict are operational actions, the identical reasoning every other *_MANAGE permission already establishes). Seeded automatically via the existing idempotent identity.bootstrap.seed_rbac.

§3.5 REST surface (api/eval_platform.py + api/eval_platform_schemas.py)

Seven routes under /eval-platform, all requiring a local account:

Cross-tenant access to any run-scoped route is denied with the same 404 a genuinely nonexistent run would get.

§4. TEST

One real test-flakiness issue was found and fixed before it could land as a non-deterministic test: SQLite’s CURRENT_TIMESTAMP server-default only has second-level resolution, so two runs created within the same wall-clock second in test_list_runs_orders_most_recent_first would tie and make the ORDER BY created_at DESC secondary ordering non-deterministic. Fixed by setting created_at explicitly on the two test rows after creation (never possible through the repository’s own public API, which always lets the database stamp it) – a test-only determinism fix, not a change to the repository’s real behavior; Postgres’s own now() has microsecond resolution, so production never hits this.

Testing summary: 150/150 new tests passing (21 + 11 + 19 component-benchmark-adjacent unit tests, 19 + 11 + 21 eval-platform-specific) plus 62/62 component-benchmark cases across 9 domains (up from 28/28 across 4). ruff check/black --check clean on every touched/new file (one auto-fixable import-order finding, fixed). mypy clean on every new production module after fixing two real Optional-narrowing gaps mypy itself found in cases_calculations.py (a direct getattr(x.y, ...) where x itself could legitimately be None, which would have raised AttributeError at runtime had the engine ever failed to produce a VARIANCE/MEDIAN finding for this input shape – fixed by extracting the possibly-None intermediate value once and guarding it explicitly) and one real frozenset[Permission]-vs-frozenset[str] type mismatch in eval_platform/policy.py (fixed by matching governance_center.policy’s own established frozenset[str] + .value in ... convention, the real return type identity.repositories.users.get_user_permissions actually has). The one remaining mypy finding across every file this prompt touched (db/schema_introspection.py:342) is confirmed pre-existing and untouched by this session via git diff --stat.

Full-suite regression run (pytest -q, no -k/-x filter) is tests/test_api_eval_platform.py+ tests/test_eval_platform.py + tests/test_identity_eval_platform_repository.py + tests/test_eval_component_benchmark.py + tests/test_identity_rbac.py = 150/150 confirmed green in isolation; the broader full-repo suite was also run in the background during this session (see the final report’s own “Tests and results” section for its outcome, captured after this document was written).

§5. REVIEW / FIX

Two real bugs, both caught by mypy before being caught by a test (neither was a logic bug a passing test would have masked – both were None-handling/typing gaps a passing happy-path test genuinely would not have exercised):

  1. cases_calculations.py’s variance/median cases called getattr(x.y, "attr", None) where x (variance_finding/median_finding) was itself typed AnalyticsFinding | None – a latent AttributeError waiting for an input shape where the engine legitimately produces no such finding. Fixed by extracting the possibly-None intermediate (variance_stat/ median_stat) once and guarding every subsequent access against it explicitly.
  2. eval_platform/policy.py’s authorize_eval_action was typed to accept frozenset[Permission] and checked membership via bare enum values (Permission.EVAL_MANAGE in actor_permissions) – which happens to work at runtime today only because Permission is a str-subclassed Enum and identity.repositories.users.get_user_permissions actually returns frozenset[str], a type mismatch mypy caught immediately. Fixed by matching governance_center.policy’s own established frozenset[str] + .value in ... convention exactly, rather than leaving a working-by-coincidence type contract in a security-relevant authorization function.

§6. DOCUMENT

§7. REPORT

See the final chat-turn report for the full inspected-areas/reused-components/files-changed/ API-DB-config-changes/tests-and-results/security-tenant-review/performance-cost-impact/ limitations/remaining-risks/recommended-next-prompt structure the mission’s own “Final report” section requires.