How to Configure Semantic Kernel MongoDB Prevent Delete
You can set up semantic kernel mongodb prevent delete rules by assigning custom database roles. These roles block remove and drop actions before your AI agent runs a query. Teams often connect agents to databases using standard read and write roles for speed. When a role is too broad, one bad prompt can wipe out whole collections. Giving an AI plugin full write rights puts your production records at high risk. How semantic kernel mongodb prevent delete works with database roles Semantic Kerne
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.
You can set up semantic kernel mongodb prevent delete rules by assigning custom database roles. These roles block remove and drop actions before your AI agent runs a query. Teams often connect agents to databases using standard read and write roles for speed. When a role is too broad, one bad prompt can wipe out whole collections. Giving an AI plugin full write rights puts your production records at high risk.
How semantic kernel mongodb prevent delete works with database roles
Semantic Kernel uses plugins and memory connectors to read and write data in MongoDB. The framework itself does not block specific database commands at the database engine level. Instead, MongoDB enforces permissions through role-based authorization on the target database. A database role grants privileges to perform sets of actions on specific resources. You can apply these permissions down to the collection level for tight control.
To stop deletions, you must look at how built-in roles handle data changes. The standard read role allows actions like find, listCollections, and listIndexes on non-system collections. It does not allow insert, update, remove, or dropCollection actions at all. If your AI agent only searches vector memory, the read role stops all deletes. Still, many AI workflows also need to save new chat records or embeddings.
The built-in readWrite role adds insert and update actions for saving new agent data. Yet it also grants remove and dropCollection actions on that same database. To allow writes while blocking deletes, admins build a custom database role. This custom role combines read privileges with insert and update actions on target collections. It leaves out the remove and dropCollection actions so the database rejects delete commands.
Why static database roles leave operational gaps
Database roles decide who can log in and which actions a user account holds. They work well when an app always needs the exact same level of access. Yet AI agents often run tasks on behalf of many different human users. Static connection strings force every agent action through one shared database user account. You cannot change permissions for a single request without making more database accounts.
Also, a role that blocks remove actions still allows broad update commands. An AI plugin could overwrite an existing document with empty fields using an update action. Database roles check the command type, not the specific contents of an in-flight request. They also do not mask sensitive fields like emails, phone numbers, or card numbers. When a query runs, raw data returns to the model unless masking rewrites matched fields in results.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
How to design safe agent plugins for database writes
Alongside database roles, teams should limit how Semantic Kernel plugins build database requests. Avoid giving the language model a generic tool that runs raw database queries. Instead, write small plugin functions that only perform one clear task at a time. For example, build one function to add a log entry and another to fetch records.
Never expose a delete method to the model inside your custom plugin code. Even if the model tries to delete data, no matching function will exist. Combine narrow plugin functions with a restricted MongoDB role for two layers of safety. If a prompt injection tricks the agent, the database engine still blocks any remove command.
Inspect MongoDB wire traffic in flight
Built-in MongoDB roles govern collection access at setup time. They cannot score command risk per call or mask sensitive document values on the fly. By design, hoop.dev is an open-source proxy that sits next to MongoDB as a sidecar for your MongoDB. It reads every command from mongosh, drivers, or agent tools.
First, hoop.dev guardrails block bad deletes, drops, and write pipelines. Next, hoop.dev data masking rewrites sensitive values in returned documents based on your rules and logs each decision. Explore the repo on GitHub.
Frequently asked questions
Does the MongoDB read role stop an AI agent from deleting data?
Yes, the built-in read role only allows search actions like find and listCollections. It blocks insert, update, remove, and dropCollection actions across all non-system collections in that database.
Can the built-in readWrite role prevent delete commands?
No, the standard readWrite role includes both the remove and dropCollection privilege actions. To allow writes while blocking deletes, you must create a custom role without those actions.
Can I restrict delete actions on a single MongoDB collection?
Yes, MongoDB roles can grant privilege actions down to the individual collection level. You can allow insert and update on one collection while blocking remove everywhere.
Related guides
In this post