Governed retrieval before model judgment
The chat model may pick tools or draft prose, but entitlements, SQL guards, and chunk-id intersection must decide what data exists and what may be cited.
An endorsement may change how a policy applies. To answer correctly, the assistant needs the right policy, the linked endorsement and the appropriate claim context. The existence of a relevant-looking passage alone is not enough.
A claims analyst in the Meridian Mutual workbench asks how the general-liability limits on policy POL-TX-GL-0009 change once the endorsement tied to claim CLM-TX-GL-0044 applies. The Databricks App in stage 06 forwards that question to the served meridian-claims-agent endpoint with the analyst’s on-behalf-of-user token. Inside 05-agent-serving/src/agent.py, the only model-driven step is _call_model: it may call search_documents, which wraps stage 04’s retrieve(), or query_claims, which runs a guarded SELECT through a SQL Warehouse. The transcript grows turn by turn until the model returns an answer without requesting more tools, or until MAX_TOOL_TURNS stops the loop.
Stages 02–04 are pipelines, not agents. Ingestion, chunking, and hybrid Vector Search are deterministic jobs. 04-production-rag/src/answer.py calls the chat model once, after evidence is fixed, and rejects any citation whose chunk_id was not in the retrieved set. Only stage 05 is described in the root README as an agent, because only _call_model chooses among tools each turn.
The claim is that document intelligence stays governable when hard controls own identity, schema boundaries, and citation membership, and the model is confined to tool choice and wording inside evidence the code already admitted. A stronger model does not replace validate_claims_sql, build_entitlement_filters, or extract_citations. Meridian Mutual, its policies, and its claims book are synthetic; this repository documents patterns against Databricks APIs and does not claim production metrics.
The argument
- Entitlements and SQL shape are host decisions. Jurisdiction filters, abstention thresholds, and SELECT-only
claimsaccess are enforced in Python before or beside the model. - Stage 04 is a grounded lane, not a planner.
retrieve()andgenerate_answer()are deterministic; the chat model fills prose only inside chunks that passed the score floor. - Stage 05’s agent is narrow.
ClaimsAgent._call_modelpickssearch_documentsand/orquery_claims; handlers adapt retrieval and execute SQL, they do not replan governance. - Regression is scripted, not anecdotal.
eval/golden_set.jsonlplusevaluate_retrieval.main()define floors for recall, MRR, and coverage; the harness does not embed prior run scores.
Who is allowed to decide
The tempting layout gives the model one endpoint and asks the prompt to behave. This stack splits the question into layers with different owners. Unity Catalog holds catalogs meridian_dev and meridian_prod, schemas raw, documents, claims, and retrieval, and row filters on jurisdiction plus column masks on claimant and policy holder fields per docs/domain.md. Those controls apply when query_claims calls WorkspaceClient().statement_execution.execute_statement under the caller’s identity—the app README states that on-behalf-of-user auth is what makes row filters and masks apply per analyst rather than per app.
Document retrieval is a separate enforcement point. 04-production-rag/src/retriever.py documents that Vector Search runs under a service principal, so the metadata filter from build_entitlement_filters stops a claims_analysts caller from retrieving chunks outside the jurisdictions granted in claims.analyst_jurisdiction. An empty grant raises EntitlementError rather than searching unfiltered. platform_admins get another EntitlementError for standing content read. Managers and compliance officers pass without a jurisdiction restriction in that function.
ClaimsAgent._call_model chooses tools; filters and SQL guards run in deterministic code.The figure’s dashed box is the served consumption path. The Streamlit app never implements a tool loop; it is a client. ClaimsAgent binds SEARCH_DOCUMENTS_SCHEMA and QUERY_CLAIMS_SCHEMA once at construction and caps each request at four tool round-trips. log_agent declares the vector index and chat endpoint as logged resources so agents.deploy can provision credential passthrough instead of a static token, as described in 05-agent-serving/README.md. validate_claims_sql in 05-agent-serving/src/tools.py is regex-based: it rejects DML/DDL keywords and any FROM/JOIN target outside the configured catalog’s claims schema. That guard restricts which tables may appear; Unity Catalog still decides which rows and masked columns return. Neither layer substitutes for the other.
Inside the loop, tool_choice is auto and temperature is 0.1, but the handlers are dumb adapters. load_stage04_retriever imports retrieve from the sibling stage folder without duplicating ranking logic. Stage 04’s README is explicit that there is no model-driven action loop there: the workflow decides how many chunks to fetch, what to reject, and when to abstain. Refusal for out-of-scope questions is stated in the system prompt in agent.py, and the stage 05 README labels that as prompt-enforced, not code-enforced—a deliberate risk call documented there.
Upstream, 01-lakehouse-foundation owns grants, row filters, and masks; 03-vector-search owns document_chunk_index refresh; stages 04 and 05 query that index and never rebuild it per docs/domain.md cross-stage handoffs. That ordering matters for authority: governance and index lifecycle are job and SQL concerns; only the served agent endpoint interleaves model turns with reads.
What the evidence shows
It is easy to describe hybrid search, citation brackets, and MLflow traces as if each had been measured in a live workspace. The repository is explicit that it does not claim measured workload results or embedded evaluation scores. What is checked in source are contracts, guards, and the golden-set harness.
generate_answer rejects citations outside the qualifying evidence set.The second figure links draft text, citation tokens, evidence ids, and a golden-set fixture; generate_answer rejects bracket tokens that are not in the qualifying evidence set. Every factual sentence must end with [chunk_id] per the stage 04 README. After generation, extract_citations gathers bracket tokens and any id not in the qualifying evidence set raises UngroundedCitationError. That is a hard failure, not a warning—the README argues an ungrounded citation is worse than abstention because it looks verifiable.
Abstention is equally structural. MIN_EVIDENCE_CHUNKS = 1 means when nothing meets DEFAULT_SCORE_THRESHOLD of 0.55, the lane returns ABSTENTION_MESSAGE without calling the chat model. retrieve() already filters at the threshold and dedupes with max_per_document default 2 so one long policy cannot crowd out an endorsement chunk—a shape the multi_chunk golden cases exercise. Instruction ordering in answer.SYSTEM_PROMPT puts grounding rules before the evidence block so chunk text cannot precede the citation contract, which the stage 04 README treats as injection-resistant structure rather than a stylistic choice.
The abstain_expected rows are one stock-ticker question, a Washington (WA) jurisdiction filter, and fabricated claim CLM-ZZ-0000. For those, successful retrieval is defined as returning no qualifying chunks; surfacing any hit fails recall_at_k by construction in evaluate_retrieval.py.
evaluate_retrieval.py gate index changes before stage 05 serving.The third figure is the regression instrument, not a scoreboard. eval/golden_set.jsonl holds fourteen synthetic cases with types direct, multi_chunk, filtered, and abstain_expected. For abstain_expected, expected_chunk_ids is empty: recall_at_k treats retrieval as correct only when nothing is returned. DEFAULT_THRESHOLDS sets floors at recall_at_k 0.7, mrr 0.6, and coverage 0.8; main() prints breakdowns and returns exit code 1 when check_thresholds reports a violation. The groundedness LLM judge is defined in the same module but intentionally excluded from the default gate because it would be nondeterministic and expensive—another example of choosing deterministic CI over model judgement for ship decisions.
On the agent side, tool failures become {"error": ...} tool messages so a rejected SQL string does not 500 the endpoint. Results truncate at MAX_TOOL_RESULT_CHARS and chunk text at the search tool boundary so one fat query does not dominate later turns. MLflow span names are claims_agent.predict, claims_agent.chat_completion, and claims_agent.tool_call on predict, _call_model, and _invoke_tool. Stage 05's README positions those traces as the evaluation surface for tool-selection review, not a second benchmark file.
The turn we scripted
Without a checked-in unit test module, the closest fixed "turn" is a golden-set case executed by run_all in evaluate_retrieval.py. The row asks how POL-TX-GL-0009 limits change once the endorsement referenced in claim CLM-TX-GL-0044 is applied. Filters pin jurisdiction to TX and line_of_business to general_liability. Expected evidence is policy-tx-gl-0009:2 and endorsement-tx-gl-0009-e1:1. That expected pair is one chunk from each of two documents, the shape that max_per_document (default 2) protects by capping chunks from a single document_id.
The scripted retrieval path is: build a RetrievalRequest with the case query and filters, call similarity_search on meridian_dev.retrieval.document_chunk_index through endpoint meridian-vs with query_type="HYBRID", drop hits below 0.55, dedupe per document_id, return chunk ids. If the case were passed to generate_answer, qualifying chunks would be numbered and extract_citations would reject bracket tokens missing from that set; no drafted answer is recorded.
No tool trace for this question is in the repo; the prompt uses search_documents for document text and query_claims for structured claims data, and tells the model to call both when the question spans both. The README says a one-shot router between a RAG chain and a SQL chain cannot represent a mixed question without another hand-written orchestration path. The README’s composition note is that stage 05 does not replace stage 04; it wraps retrieval as one tool option. log_and_deploy.py logs ClaimsAgent with declared dependencies on the vector index and chat endpoint. register_agent registers {catalog}.retrieval.claims_agent, which is meridian_dev on the dev target and meridian_prod on prod. agents.deploy creates or updates the meridian-claims-agent endpoint with scale_to_zero=True, trading cold start for idle cost—acceptable because lookups are analyst-initiated.
The one check to copy
Copy the regression gate, not the insurer nouns. Point evaluate_retrieval.main() at your index and endpoint, load a fixture with explicit expected chunk ids and abstain rows, compute recall_at_k, reciprocal_rank, and coverage, then fail the job when aggregates breach configurable floors.
def check_thresholds(
breakdown: dict[str, dict[str, float]],
coverage_value: float,
thresholds: dict[str, float],
) -> list[str]:
"""Compare a metrics breakdown against regression floors."""Pair that retrieval gate with the answer-lane intersection:
cited = extract_citations(raw_text)
ungrounded = [chunk_id for chunk_id in cited if chunk_id not in evidence_id_set]
if ungrounded:
raise UngroundedCitationError(
f"response cited chunk_id(s) not present in retrieved evidence: {ungrounded}"
)For the SQL tool, copy the two-step pattern: validate_claims_sql before execution, then warehouse execution under the caller’s UC identity. A benefits desk would swap schema names and golden queries; the shape—fixture-driven retrieval floors plus citation membership plus read-only SQL guard—stays the same.
The named entry point is evaluate_retrieval.main in 04-production-rag/resources/eval_job.yml. That job runs evaluate_retrieval.py and fails when check_thresholds reports a violation; it does not wire a gate in front of the served agent.
Close
Lakehouse document intelligence is often sold as "RAG plus an agent." In this reference build, the honest split is tighter. Pipelines move PDFs into document_chunk_index, filter retrieval by role, abstain when scores fail, and postcheck citations in stage 04. One served component—the ClaimsAgent loop—lets the model choose between document search and governed SQL, bounded at four turns, with deterministic tools underneath. The other stages also include the stage 06 Streamlit workbench and the stage 07 Genie space, along with jobs, SQL, and the retrieval harness.
Ship changes when the golden set still clears check_thresholds, ungrounded citations still raise, and query_claims still rejects writes and foreign schemas—even if the chat model gets better at phrasing the analyst’s answer.
How is this page?
Last updated on