How to Configure CrewAI SQL Server Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a crewai sql server prevent delete workflow, restrict the database user role. You must remove row removal rights from the account that your agents use. Many teams connect AI agents to databases using shared admin accounts during testing. Those broad roles let an agent drop tables or remove rows by mistake. A safer setup uses strict database permissions from the very first day. How to set up crewai sql server prevent delete roles Your first step happens inside SQL Server rather than

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To set up a crewai sql server prevent delete workflow, restrict the database user role. You must remove row removal rights from the account that your agents use. Many teams connect AI agents to databases using shared admin accounts during testing. Those broad roles let an agent drop tables or remove rows by mistake. A safer setup uses strict database permissions from the very first day.

How to set up crewai sql server prevent delete roles

Your first step happens inside SQL Server rather than inside your Python code. Every database user maps to a server login or runs as a contained user. A login in the master database works well when one account reaches many databases. A contained database user stays inside one database and uses its own password. A database admin must turn on contained databases on the server first.

Once you create the user for your agent, you assign its permissions. SQL Server includes fixed database roles for quick setup. The standard read role lets a user read all data from all user tables. It also lets the agent read all views in that database. If your agent only answers questions, this read-only role is the best choice. You can also add the deny write role to block all data changes.

Sometimes an agent needs to insert new records or update existing status fields. The standard write role allows adding, changing, and deleting data across all user tables. Because fixed database roles cannot be changed, the write role always allows deletes. To allow inserts while blocking deletes, skip the fixed write role. Instead, create a custom role that grants read, insert, and update rights only. You then explicitly deny delete rights on the tables your agent touches.

Why native roles leave gaps for agent queries

Database roles control who can log in and which table actions are allowed. They work well as a baseline defense against destructive commands. Still, native roles do not inspect what individual statements do in flight. An agent with read rights can still run a massive join that locks tables. An agent with update rights can overwrite every row if it omits a filter.

Also, database roles apply the same static rules to every query from that user. When a CrewAI team runs, multiple specialized agents often share one database connection string. One agent might draft reports while another agent logs task outputs. Giving the shared database user update rights gives every agent in the crew update rights. Native roles also cannot mask sensitive fields like emails or phone numbers in results.

SQL Injection Prevention + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why prompt rules cannot replace database controls

Some builders try to stop deletes by writing rules inside the agent prompt. You can tell a CrewAI agent to never run a delete statement. You can also build separate tools for reading data and writing data. These steps guide the model, but they do not enforce a hard security boundary.

Large language models generate SQL text based on task goals and user inputs. If a prompt is vague, the model might still output a delete command. If the database user has delete rights, SQL Server will run that command right away. Prompts express intent, while database permissions and runtime checks enforce real rules.

Add runtime guardrails beside SQL Server

Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev runs beside the database as a sidecar for your SQL Server and checks TDS traffic without changing how clients log in.

With hoop.dev SQL Server controls, rules refuse banned statements before they run and can hold risky queries for human review. Matched sensitive values in supported result columns are masked before they reach the client. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.

Frequently asked questions

Can I change the fixed write role in SQL Server to block deletes?

No, SQL Server does not let you change the permissions of fixed database roles. To allow writes without deletes, use a custom role or add explicit deny rules.

Should I use a server login or a contained user for my CrewAI agent?

Use a contained database user if the agent only needs one or a few databases. Use a login in master if the agent must query many databases on the server.

What happens if an agent needs to read some tables and update others?

Avoid broad database-wide write roles when an agent only updates a few tables. Grant read rights where needed and grant update rights only on the specific target tables.

The query runs. The emails stay hidden.