Act as a Principal AI Architect, Enterprise Data Platform Architect and Senior Product Engineer.
Create a governed registry for prompts, agents and analytical policies. Inventory existing prompt templates and agent definitions first. Version artifacts, owners, variables, required tools, compatible models, evaluation suites and deployment status. Validate unsafe composition, missing variables and unapproved tools. Support draft/test/approved/deployed/retired states and rollback. Add regression tests proving prompt changes cannot weaken security or semantic governance.
INSPECT → PLAN → IMPLEMENT → TEST → REVIEW → FIX → DOCUMENT → REPORT
The single most important inspection finding: Prompt 44 had already
built the registry’s entire lifecycle, one session earlier.
governance_center/ (commit c86d1f7) ships GovernanceStage
(draft → testing → evaluating → approved → deployed, plus
rolled_back/rejected/retired), VALID_STAGE_TRANSITIONS, a real
rollback action, per-version rows on
identity.models.GovernanceAssetVersion with owner/version/stage,
an append-only GovernanceEvent audit trail, tenant-scoped ABAC
(governance_center/policy.py), two RBAC permissions, and 17 REST
routes — across seven asset types that already include prompt, agent
and policy.
So this mission’s “version artifacts, owners, deployment status” and “support draft/test/approved/deployed/retired states and rollback” clauses were already satisfied. Building a second registry would have violated the first mandatory control outright.
What genuinely did not exist:
| Mission clause | State before this prompt |
|---|---|
| “Inventory existing prompt templates and agent definitions first” | Nothing enumerated them. Prompts were 15 private constants scattered across 8 modules; agent definitions lived in one dict nothing else read. |
| “variables, required tools, compatible models, evaluation suites” | GovernanceAssetVersionSnapshot.config is deliberately free-form JSON, documented as “stored and displayed, never evaluated”. No typed field for any of these. |
| “Validate unsafe composition, missing variables and unapproved tools” | No validation of any kind existed for artifact content. |
| “Regression tests proving prompt changes cannot weaken security or semantic governance” | No test anywhere asserted anything about a live prompt’s content. |
Also inspected and reused rather than reimplemented:
security/injection_patterns.py (the shared pattern dict, 4 existing
consumers), agent.multiagent.agents.SPECS (13 live specialists),
agent.multiagent.tools’ TOOL_* names and
agent.tools.definitions.build_default_registry (two separate tool
registries, 18 names between them), agent.model_registry’s notion of
an allowed model, db.schema_introspection’s sha256-prefix
fingerprint convention, and agent.provenance.DataTruthLevel.
Three new modules inside governance_center/ — not a new package,
because this is the existing registry’s typed-artifact layer, not a
second registry:
governance_center/safety.py — six named SafetyInvariants, each
with a detector anchored on real phrasings this codebase’s own prompts
use, plus eight WEAKENING_PATTERNS recognizing text that actively
subverts a control. Presence-of-a-bad-instruction and
absence-of-a-good-one are kept as two independent questions on
purpose. SECURITY_INVARIANTS is the subset whose removal blocks;
NO_FABRICATION/CITATION_REQUIRED are reported instead.governance_center/artifacts.py — PromptArtifactSpec,
AgentArtifactSpec, AnalyticalPolicyArtifactSpec, each frozen and
extra="forbid", covering template/variables/required tools/
compatible models/evaluation suites/declared invariants.
parse_artifact_spec gives Prompt 44’s config a typed reading for
these three asset types only (TYPED_ASSET_TYPES); the other four
keep their original free-form behavior byte for byte.
extract_template_variables uses string.Formatter — the parser
str.format itself uses — so json escapes are
correctly not variables and {cfg.name} resolves to its root.governance_center/inventory.py — the mission’s “inventory first”
clause as executable code. 15 prompts, 13 agents, 6 analytical
policies, each resolved from the live object at call time
(importlib + the real constant; the real SPECS dict; real
Settings fields), never transcribed. A named artifact that has moved
raises InventoryUnavailableError rather than being skipped, so the
inventory cannot silently shrink into a falsely-clean picture.governance_center/validation.py — pure, I/O-free. 14
ViolationCodes across missing/undeclared/positional variables,
unapproved tools, unknown models, unknown evaluation suites, dropped
safety invariants, unsafe composition, agent tool-privilege and
truth-level escalation. One ERROR invalidates the whole artifact; no
partial trust, matching analytics.scenario/optimization.validator.API surface (api/governance.py, api/governance_schemas.py):
GET /governance/inventory — the live inventory plus the valid
tool/model/suite names, so a reviewer sees them up front.POST /governance/assets/validate — validate a candidate without
persisting. Returns 200 with the report either way; only a
lifecycle action refuses.(a) The validator rejected this codebase’s most security-conscious
prompt. Running INJECTION_PATTERNS as a blocking check over prompt
templates flagged agent.llm_client._system_prompt three times — for
quoting the attacks it defends against ('ignore previous instructions',
'you are now in developer mode') and for prohibiting a connection
string in generated SQL. All three were defensive mentions. That pattern
set is tuned for untrusted user input, where a match means someone is
attempting the attack; an authored prompt discussing security is the
opposite context, and no fixed pattern list distinguishes the two
reliably. Fixed by stripping quoted spans before scanning and
downgrading the finding to a warning;
UNSAFE_COMPOSITION (phrased around imperative instructions, zero false
positives across all 15 live prompts) carries the blocking weight
instead. See validation._scan_for_injection_mentions.
(b) Deleting the declaration escaped the dropped-invariant check.
Version N declares untrusted_data_framing; version N+1 declares
nothing and carries nothing — so nothing was “dropped” relative to its
own empty declaration, and it passed. This defeated the mission’s
central requirement. Fixed by making the required set monotonic across
versions: _enforce_artifact_validity takes a predecessor_config
(the stored draft being edited, or the currently-deployed version of the
same asset key) and folds its declared and carried invariants into the
required set, so a successor can only ever add. Pinned by four tests in
TestSuccessorVersionsInheritTheirPredecessorsControls.
A third issue was found and left alone deliberately — see §6.
| File | Cases | Scope |
|---|---|---|
tests/test_governance_registry.py |
60 | Typed specs, template-variable extraction, every safety detector, the live inventory, and every validation rule. Fully offline. |
tests/security/test_prompt_registry_cannot_weaken_security.py |
41 | The mission’s own required regression suite, in two halves (below). |
The security suite’s two halves:
EXPECTED_LIVE_INVARIANTS pins, per
prompt, which invariants it must carry — pinned explicitly rather
than derived from the live text, because a derived expectation would
pass no matter what the prompts said. Editing agent/llm_client.py
to drop the untrusted-data framing now fails CI with a diff naming
the dropped control. Also asserts that no live prompt contains a
weakening instruction, that every SQL-pipeline prompt carries the
untrusted-data framing as a group, that governed-metric precedence is
still stated somewhere live, and that every live artifact validates
against itself without errors (the assertion that caught bug (a)).test_the_deploy_gate_revalidates_the_stored_config
weakens a row directly in the database, bypassing the API’s edit
gate entirely — the only way to distinguish “deploy re-validates”
from “deploy trusts that creation validated”.Plus: both new routes reject unauthenticated and non-governance callers;
the inventory never returns live prompt template text (asserted against
a 60-character probe of every real template — shipping the prompt set
over HTTP would make every prompt’s own NO_PROMPT_DISCLOSURE rule
pointless); a refusal never echoes the submitted template back; and
cross-tenant access to the new paths stays a 404.
_authorize → authorize_governance_action chokepoint with
GovernanceAction.LIST — the action designed for a route with no
specific target. (VIEW was wrong and correctly denied: it always
tenant-matches a resolved version.) No new permission was added; no
existing route’s permission changed.config or template text; a 422 body contains the validator’s own
messages, not the submitted template.PolicyRule is a typed (subject, operator, value)
triple, so there is no field an authored expression could occupy.agent/llm_client.py still uses its own in-code constants. Making a
database row the system prompt would turn every write path into the
registry — and every mistake in review — into prompt injection with
full pipeline reach. The registry governs review/approval/rollback of
candidate artifacts and detects drift in live ones; promoting a
reviewed artifact into the runtime remains a code change.governance_center/safety.py says so in its own docstring. It catches
accidental weakening; agent/sql_validator.py’s AST allowlist and the
RBAC/restricted-column gates remain what bound consequences.test_a_brand_new_key_declaring_nothing_gets_only_self_consistency_checks.rag.retriever._GRADE_SYSTEM_PROMPT receives raw document excerpt
text (chunk_text[:500]) and states no untrusted-data framing;
_REWRITE_SYSTEM_PROMPT likewise states none (it receives filenames
only). Blast radius is bounded — the grader returns a single YES/NO
that gates retry/rewrite, and the rewriter returns a search string;
neither reaches generated SQL or the user’s answer. Left unchanged
because this pass does not edit live prompt wording (CLAUDE.md pins
several of these texts to measured benchmark numbers), and recorded as
set() in EXPECTED_LIVE_INVARIANTS so the gap is visible rather
than hidden. Recommended as the next prompt’s first fix.AgentSpec.kind’s own docstring is stale — it lists four kinds,
but semantic is a live "retrieval" agent. AgentArtifactSpec
takes the real set from the live specs and pins it with a test; the
stale docstring itself was not edited.test_results/
evaluation_results remain caller-reported, exactly as Prompt 44
shipped them.tests/test_api_governance.py::test_list_filters_by_asset_type created
a prompt-typed draft with {"provider": "ollama"} — a model’s
config. That is now correctly a 422. The test’s own assertion (list
filtering by asset type) is unchanged; only its fixture config was
corrected, with a comment explaining why. This is an intentional,
disclosed behavior change for the three typed asset types.
The working tree contains a prior session’s partially-finished work in
eval/component_benchmark/: runner.py imports four new cases_*.py
modules (cases_anomaly_root_cause, cases_calculations,
cases_forecasting, cases_groundedness) but registers none of them in
_DOMAIN_MODULES, so ruff reports four unused imports and the cases
never run. An edit this prompt had briefly made to that file was backed
out, and the inconsistency is not part of this change — it is
reported for a deliberate decision rather than silently completed or
deleted. governance_center.inventory.known_evaluation_suites
discovers suites by globbing instead, which needs no edit to that file.
Zero LLM calls, zero database queries in the validator, and zero network
access anywhere in this feature. The inventory reads in-process module
state plus the already-cached Settings. GET /governance/inventory
and POST /governance/assets/validate perform no query beyond the
permission lookup every governance route already does. The four
lifecycle gates add one sha256 per prompt plus a bounded set of regex
scans — microseconds against a request that was already doing a database
write. create_draft adds one indexed get_current_deployed lookup.
Prompt 46 — close the two unframed RAG prompts and wire the registry’s
drift detection into CI. Specifically: add untrusted-data framing to
rag.retriever._GRADE_SYSTEM_PROMPT (and re-pin
EXPECTED_LIVE_INVARIANTS), and add a CI step that fails on any live
prompt fingerprint change not accompanied by an updated expectation, so
prompt drift is caught at review time rather than only by a test a
developer might not run. A second, independent candidate is the
component-benchmark inconsistency in §8.