Agentic AI systems violate the implicit assumptions of database design
TL;DR Highlight
AI Agents shatter a 40-year assumption—that databases only accept deterministic queries from humans—and this post details specific defensive patterns to mitigate the resulting risks.
Who Should Read
Backend/data engineers granting or considering database access to AI Agents, especially those designing systems connecting production DBs and Agents.
Core Mechanics
- Database architecture implicitly assumes the caller is an application executing deterministic code written by humans. Queries are reviewed, writes are intentional, and issues are caught by people—an assumption held for four decades.
- AI Agents dynamically generate queries based on their reasoning path, potentially executing never-before-seen queries like a five-table join, holding connections while contemplating results, and then running entirely different follow-up queries, breaking existing indexes and connection pool settings.
- The first line of defense is setting statement timeouts at the DB role level, not the application level. Forcing a timeout on an agent-specific role—e.g., `ALTER ROLE agent_worker SET statement_timeout = '5s'`—prevents infinite reasoning loops from exhausting DB resources.
- The `idle_in_transaction_session_timeout` setting is also crucial. Agents genuinely open transactions, pause reasoning mid-process, and without this timeout, those connections remain indefinitely occupied.
- Agent writes aren't 'reviewed intentional writes'. A documented incident involved an Agent interpreting HTTP 200 and an empty result (a silent failure due to DB connection pool exhaustion) as 'success', approving 500 transactions with incomplete data.
- All tables accessible to Agents should default to soft delete. Add `deleted_at`, `deleted_by` (e.g., 'agent:customer-support-v2'), and `delete_reason` columns, and expose only views like `active_orders` to Agents. The `deleted_by` column enables debugging queries like 'show everything agent X deleted two hours ago'.
- High-stakes tables—financial records, inventory changes, user state—should be designed as append-only event logs. Agents only INSERT new states, never UPDATE or DELETE, preserving a complete audit trail of who did what and when.
Evidence
- "Most comments strongly rejected the premise of granting Agents direct write access to production DBs, with many arguing that stored procedures and API layers exist precisely to prevent this. One analogy compared it to letting an intern perform live migrations in production."
How to Apply
- If Agents need DB access, connect them read-only to a near real-time replicated OLAP DB instead of the production OLTP DB. For writes, restrict Agents to API endpoints with approval workflows—e.g., `request_to_ban_user(id)`—automatically blocking Agent mistakes.
- Create an Agent-specific DB role and enforce `ALTER ROLE agent_worker SET statement_timeout = '5s'` and `idle_in_transaction_session_timeout = '10s'` at the role level. This prevents resource exhaustion from infinite loops or connection hogging without application code changes.
- For tables Agents write to, add `deleted_at TIMESTAMPTZ`, `deleted_by TEXT`, and `delete_reason TEXT` columns for soft delete, and expose only views with `WHERE deleted_at IS NULL` to Agents. This enables future recovery and auditing.
- If Agents handle sensitive data like financial transactions or inventory, design separate append-only event log tables and allow Agents to INSERT only. Revoking UPDATE/DELETE privileges at the DB level structurally prevents accidental data overwrites or deletions.
Code Example
-- Create agent-specific role and set timeouts
CREATE ROLE agent_worker;
ALTER ROLE agent_worker SET statement_timeout = '5s';
ALTER ROLE agent_worker SET idle_in_transaction_session_timeout = '10s';
-- Add soft delete columns
ALTER TABLE orders ADD COLUMN deleted_at TIMESTAMPTZ;
ALTER TABLE orders ADD COLUMN deleted_by TEXT; -- e.g., 'agent:customer-support-v2', 'user:abc123'
ALTER TABLE orders ADD COLUMN delete_reason TEXT;
-- Expose only this view to agents (automatically filters deleted rows)
CREATE VIEW active_orders AS
SELECT * FROM orders WHERE deleted_at IS NULL;Terminology
Related Papers
Ask HN: How do you get into a flow state when using AI to code?
Claude 같은 에이전트 기반 AI 코딩 도구가 보편화되면서 개발자들이 기존의 몰입 상태(flow state)를 잃어버리고 있다는 문제를 공유하고, 커뮤니티에서 각자의 대처 방법을 논의한 스레드.
Claude Desktop spawns 1.8 GB Hyper-V VM on every launch, even for chat-only use
Claude Desktop Windows 앱이 사용자가 AI 코드 실행 기능(Cowork)을 쓰지 않아도 실행 시마다 자동으로 1.8GB짜리 Hyper-V 가상머신을 생성해 메모리를 잡아먹는 버그가 보고됐다.
Apache Burr: Build reliable AI agents and applications
LangChain 같은 복잡한 프레임워크에 지친 개발자들을 위해 순수 Python으로 AI 에이전트와 상태 머신을 만들 수 있는 Apache 인큐베이팅 프레임워크다. 상태 관리, 관측성, Human-in-the-Loop 등을 DSL 없이 제공한다는 점이 특징이다.
A €0.01 bank transfer could compromise a banking AI agent
유럽 2위 디지털 뱅크 Bunq의 AI 어시스턴트에서 발견된 간접 프롬프트 인젝션 취약점으로, 단돈 €0.02 송금만으로 사용자에게 피싱 공격을 자동 실행할 수 있었다.
Grit: Rewriting Git in Rust with agents
GitButler 팀이 AI 에이전트 스웜을 활용해 Git을 Rust로 처음부터 재작성한 Grit 프로젝트를 공개했는데, GPL 라이선스 문제와 실용성 논란이 커뮤니티에서 크게 일고 있다.
Show HN: Claw Patrol, a security firewall for agents
AI 에이전트가 실행하는 SQL, kubectl, HTTP 요청을 프록시에서 가로채 HCL 규칙으로 허용/차단/사람 승인 요청을 할 수 있는 오픈소스 보안 게이트웨이. 에이전트가 프로덕션 환경에서 위험한 작업을 실행하기 전에 제어할 수 있어 중요하다.