01
Review a Read-Only PostgreSQL MCP Tool Before You Ship It
Review database permissions, tenant identity, query time and response size in a Rust MCP tool. Use a real restricted PostgreSQL role to check the boundaries.
Evals, retrieval, tools, and observability
A software-engineering view of AI-enabled products: where models help, where deterministic boundaries remain necessary, and how to operate the whole system responsibly.
A useful AI feature is still a production system. It depends on permissions, identity, current data, tool contracts, latency budgets, evaluation, and a recovery path when a probabilistic component behaves differently than expected.
This series focuses on those engineering boundaries. The model is important, but it is one component inside a system that still needs clear invariants and evidence that it works.
01
Use models for useful ambiguity, while permissions, state transitions, money, and irreversible actions remain enforceable in code.
02
Measure retrieval, tool selection, outputs, latency, and cost against representative tasks instead of judging a demo by feel.
03
Record the inputs, versions, sources, tool calls, and decisions needed to explain and improve a production result.
Entry points into this subject, ordered as a reading path.
01
Review database permissions, tenant identity, query time and response size in a Rust MCP tool. Use a real restricted PostgreSQL role to check the boundaries.
02
Your tenant has enough documents, but an HNSW query returns too few. Compare real plans, iterative scans, and an exact fallback without weakening access checks.
03
Ship readiness for an AI feature is one artifact per failure class, each with a stated minimum bar and a stated way it can be invalidated. Built here with a runnable 300 item fixture.
04
Agent retries must reuse one logical action identity and reconcile uncertain effects. An effect ledger makes autonomy bounded, inspectable, and recoverable.
Through the layers
Roll out one narrow internal assistant before adding write actions. Read-only still requires authorization, output limits, and checks against private-data exposure.
Through the layers
Resolve tool credentials from trusted server context. A model-selected account must be checked against the acting user's current permissions before any secret is used.
Through the layers
Design a small tool-audit event around identity, policy, decision, and outcome. Test secret leakage in errors as well as normal logs.
Through the layers
Build tool manifests for the current task instead of exposing an entire backend. Keep independent server authorization because hiding a tool does not prevent a fabricated call.
Through the layers
An error response does not prove that a tool did nothing. Validate and authorize before effects, then assert unchanged storage and zero external calls after rejection.
Through the layers
An automatic model fallback should preserve actor scope, tools, approvals, and budgets. Never turn a provider failure into a switch to an administrative execution context.
Through the layers
Capture agent mail effects in a test adapter and keep production credentials out of the environment. A prompt telling the agent to stay in test mode is not an enforcement boundary.
Through the layers
A reference flow for keeping user identity, tenant, audience, and allowed actions attached to every AI tool call without trusting the model to enforce permissions.
Through the layers
Structured model output is not trusted application input. Validate syntax, semantics, authorization, and effect policy again at the tool execution boundary.
Through the layers
An agent can write outside its job through a privileged file helper. Let trusted code choose destinations and authorize report downloads.
Through the layers
Reject a model-selected hostname before lookup, check every returned address, and preserve the chosen IP and TLS hostname in a Node HTTPS request.
Through the layers
Give a trusted Rust file tool one directory handle. Check allowed reads, traversal, and outward symlinks without claiming the library confines arbitrary code.
Through the layers
Follow a control request from its credential to a job inspection. Localhost and Host headers cannot replace authentication or authorize another job.
Through the layers
Follow a constructed README attack from a proposed export to a denied tool call, and check that the downstream service performs no forbidden effect.
Through the layers
Before I type a word, my coding agent already has instructions from files, hooks, plugins and online services. I list who wrote each one, which ones can change without a commit, and how to review them.
Through the layers
I tested which instruction files Claude Code 2.1.325 really loads. AGENTS.md works alone but is skipped next to a CLAUDE.md, and a nested AGENTS.md arrived inside a tool result in my test, where a small model sometimes ignored it.
Through the layers
I tested one CLAUDE.md rule, never run git push, in 81 Claude Code runs, with and without a deny rule and a hook. The sentence held every time. The gaps were in the other layers.
Derived state
Bound tool results before they become model context or logs. Use explicit pagination or overflow errors so partial data cannot look like a complete answer.
Derived state
Show how a changing GitHub Actions build argument refreshes time-dependent pages while the dependency installation stays reusable.
Derived state
Use a small explicit dependency graph, a transitive selector, and a required-result gate that rejects failed or missing selected checks.
Interrupted execution
Understand GitHub Actions concurrency groups, repeated PR cancellation, and the different queue policy an active deployment needs.
Interrupted execution
A real scheduled deployment failed while unpacking its Docker image. Follow the protected image cleanup, portable-shell repair, and live checks.
Interrupted execution
Compare waiting for one process with cleanup on completion, timeout, cancellation, and launcher failure. Give the whole job an independent supervisor.
Measurement
Capture a small regression fixture before changing code or asking an agent for a fix. Prove that the test detects the original failure and preserves the real requirement.
Measurement
Keep reproducible failures in a versioned evaluation set. Retire obsolete cases with a recorded reason, and separate requirement changes from attempts to improve a release score.
Measurement
Compare important workflows as well as the overall evaluation result. Report case counts and uncertainty so an aggregate gain cannot hide a smaller critical regression.
Measurement
A simulation of a real 5 point improvement showing how often a fixed eval threshold gives a random red build, and why a paired comparison detects the gain at a much smaller sample size.
Measurement
A working record-and-replay harness for agent tests: a JSON cassette of decisions and tool results, deterministic replay with zero live calls, and a readable diff when the trajectory changes.
Measurement
A trajectory grader for detecting unauthorized reads, duplicate effects, fabricated tool results, waste, and unsafe recovery even when an AI agent's final answer looks correct.
Measurement
A practical agreement experiment for measuring an LLM judge against human labels, including ambiguous cases, position bias, confidence, and release thresholds.
Measurement
A retrieval benchmark for separating missing evidence from generation failures using Recall@k, Precision@k, MRR, unanswerable questions, and controlled oracle context.
Measurement
A versioned evaluation matrix for separating prompt, model, retrieval, tool, and grader changes while protecting safety, quality, latency, and cost.
Measurement
A graded assertion approach for regression-testing variable AI outputs without comparing every generated word to one frozen answer.
Measurement
A measurement architecture that joins repeatable offline evals with production outcomes, safety signals, canaries, and privacy-aware review.
Measurement
A practical AI failure taxonomy that separates what happened, where it happened, its impact, and the suspected cause so teams can build useful metrics.
Measurement
A purely random sample hides rare and expensive AI failures. Combine baseline, risk-triggered, and exploratory samples without corrupting the denominator.
Measurement
A strong system prompt cannot secure retrieval, tools, authorization, retries, or side effects. Red-team the complete AI workflow and its recovery paths.
Measurement
A practical pipeline for learning from production AI failures while minimizing personal data, preserving the failure signal, and keeping evaluation fixtures reviewable.
Measurement
Use a recorded GitHub Actions run to separate setup, early feedback, and the full build before changing a slow CI pipeline.
Measurement
A trial-expiry boundary shows how code and generated tests can share the wrong assumption. Write the expected result independently.
Measurement
Replace fixed sleeps with completion and row-identity assertions, then check a delayed preview and a deliberately wrong result in CI.
Measurement
Record PR head, checked-out source, event, and workflow URL together so a valid test-merge result is not confused with stale verification.
Measurement
Separate first-review waiting, review windows, author rework, and dependency waits before asking agents to open more pull requests.
Measurement
Show a tolerated step failure in the job summary and record the owner, evidence, expiry, and restoration condition of its exception.
Measurement
Build a small PostgreSQL search trial with exact identifiers, full-text search, pgvector, and lifecycle checks before choosing another database.
Measurement
I measured rtk, a token-saving tool, inside my Claude Code setup. It gave two wrong answers, and one is still there after the update. Its hook also approved a force push without asking me, and its own savings number fell from 125.5M to 4.8M tokens.
Measurement
My site's AGENTS.md adds 1,382 tokens to every Claude Code request. I measured each part, labeled every line, and tested a slimmer version. It dropped a line that I thought was useless, and the agent tried to change the commit author.
Measurement
I sent the same 200 bank support messages through keyword rules, search, three Claude models and an agent, and measured accuracy, cost per correct answer and time. The cheapest good result came from a small model that was shown similar labeled examples.
Measurement
I turned measured token counts from a real classification test into a monthly cost range at 10,000 and 100,000 messages. The model bill went from cents to a few hundred dollars. Under my stated assumptions, the human time for wrong answers was far bigger.
Measurement
I wrote one Claude Code skill with a vague description and a specific one, then ran 60 constructed prompts. With Haiku, the vague description loaded the skill for 18 of 30 requests that needed it, the specific one for 28. Neither loaded it for a near miss.
Measurement
I built a short Claude Code skill from the Rust Failure Atlas and tested it on 30 Atlas cases with Haiku. Every fix compiled and ran, with and without the skill. In one run per case, 11 fixes with the skill changed what the program was meant to check, against 7 without it, a gap that may be noise.
Measurement
I gave a reading subagent and a reviewing subagent different models, from Haiku to Opus, and let them review a small Rust crate with three planted bugs. Every setup found all three bugs. The real differences were the cost, a handoff that the main session quietly shortened, and one data-loss bug that I had not planted.
Measurement
I gave 40 failing Rust programs to Haiku, Sonnet and Opus. Almost every fix compiled. Reading the fixes showed the real difference, and what one accepted fix cost.
Measurement
Price per token said Haiku is 40 times cheaper than Opus. My 40 Rust fixes gave other numbers. This is how I compute cost per completed task, with failed attempts, retries, escalation and the fixed overhead of every call.
Measurement
A router sends each task to a cheap model first and escalates when a check fails. I computed one from real runs on 40 Rust fixes and compared it with one strong model at low effort. It would never have escalated, and the reason was the check, not the models.
Older, introductory or narrower pieces on the same subject.
Engineering context
I help teams turn AI-enabled workflows into maintainable products with clear data, evaluation, permission, and failure boundaries.