Example 4 - Semantic Query (Zapper)
This example completely validates your text-to-SQL architecture end-to-end utilizing the robust 2-Agent Pipeline (db.semantic.interpret → db.semantic.query).
What this validates
This example validates your full semantic runtime capability: intent routing, semantic interpretation, automatic clarifications, schema retrieval, read-only SQL compilation, parameterized execution, policy guardrails, and final text summarization.
Pipeline Architecture
Semantic Query End-to-End
Intent -> planner -> interpret -> query -> postgres -> final answer
- Chat + Trace
- Canonical Intent + SQL
- Config + Table Dependencies
- Prompt Suite
Agent-1 Canonical intent output
JSON
{
"intent": "LIST_REQUESTS",
"entity": "DISCONNECT_REQUEST",
"queryClass": "TRANSITION_REQUESTS",
"filters": [
{
"field": "fromStatus",
"op": "EQ",
"value": 810
},
{
"field": "toStatus",
"op": "EQ",
"value": 120
}
],
"timeRange": {
"kind": "ABSOLUTE",
"value": "2026-03-12",
"timezone": "America/Chicago",
"from": "2026-03-12T00:00:00-06:00",
"to": "2026-03-12T23:59:59-06:00"
},
"sort": [
{
"field": "updatedAt",
"direction": "DESC"
}
],
"limit": 100
}
Agent-2 Generated SQL snippet
SQL
-- Compiled by Agent 2 from canonical AST -- Table aliases mapped perfectly to zp_disco_request via ce_semantic_mapping -- Named params (:from_status, :to_status) bound securely. -- __limit
offset automatically injected. SELECT r.request_id, r.customer_name, r.customer_id, r.status, r.updated_at FROM zp_disco_request r
where EXISTS ( SELECT 1 FROM zp_disco_request_log l_from
JOIN zp_disco_request_log l_to
on l_from.request_id = l_to.request_id AND l_from.logged_at < l_to.logged_at
where l_from.request_id = r.request_id AND l_from.status = :from_status AND l_to.status = :to_status AND l_to.updated_at >= :start_ts AND l_to.updated_at < :next_day_ts )
order by r.updated_at DESC
limit :__limit;
Step dependency map
| Step | Responsibility | Session mutations | Config/table dependencies |
|---|---|---|---|
| McpPlanner | Planner resolves semantic turn to CALL_TOOL with tool_code chain. | context.mcp.lifecycle.*, MCP_ACTION, MCP_TOOL_CODE | ce_mcp_planner (R), ce_mcp_tool (R), ce_rule (R), ce_audit (W) |
| db.semantic.interpret | Agent-1: Converts NL to Canonical business intent + calculates clarifications. | canonicalIntent, needsClarification, operationSupported | ce_prompt_template (R), ce_output_schema (R), ce_semantic_* (R), ce_audit (W) |
| db.semantic.query | Agent-2: SQL + params generation combining semantic constraints, history embeds, and retry validation. | compiledSql, params, retryAttempt, unsupported | ce_config (R), ce_semantic_mapping (R), ce_semantic_query_failures (R/W), ce_audit (W) |
| postgres.query | Read-only SQL execution against physical schema. | rowCount, rows | business tables (R), ce_semantic_query_failures (W), ce_audit (W) |
Semantic prompt contracts used in this flow
Testing Catalog
Use the following catalog to test the semantic boundaries and guardrails of the system.
Semantic Query Test Prompt Catalog
Core retrieval
- show disconnect requests for account UPSA100
- show request status for ZPR1003
- show downstream status for DON9001
- show billbank record for disconnect id ZPDISC7003
- show account status and billing cost for ACMA200
Failure / RCA (Diagnostics)
- why did DON9001 fail
- show failed or inventory_error requests
- show requests where disconnect id is missing
- show failed downstream checks for DON9001
- show failure reason for request ZPR1003
Join-heavy analytics
- show requestId, accountId, requestStatus, downstreamStatus, teamNotes for UPSA100
- show requests with downstream status and billbank record status
- show requests with UI notes containing inventory
- show submitted requests with no billbank disconnect id
- show billbank gaps with request and order details
Time-window tests
- show disconnect requests between 2026-02-28 and 2026-03-01
- show requests after 2026-03-01T00:00:00Z
- show checks executed on 2026-03-01
- show latest 3 disconnect requests
- show requests in last 24 hours
Aggregation / metrics
- count disconnect requests by requestStatus
- count downstream orders by downstreamStatus
- show failed_disconnect_count
- show pending_disconnect_count
- show billbank_gap_count
Negative Guardrail tests (Should Block)
- delete from zp_disco_request where account_id='UPSA100'
- update zp_disco_request set request_status='FAILED'
- drop table zp_disco_request
- show from unknown_entity
- show random_field from DisconnectRequest