How to Set Up Guardrails for AI Agents in Microsoft 365 to Prevent Costly Mistakes
Lokka's new Guardrails feature lets you define granular permissions for AI agents accessing Microsoft Graph, reducing the risk of unintended data deletion, modification, or costly API overuse.
Practical Summary
This guide explains how to use the experimental Guardrails feature in the Lokka MCP server to create specific permission rules for AI agents interacting with Microsoft 365. It allows administrators to control which API methods (GET, POST, DELETE, etc.) and paths an agent can access, targeting specific resources like users or sites, to prevent unauthorized changes and the associated costs.
Why It Matters
Giving AI agents broad, unchecked access to production systems like Microsoft 365 is a major operational and financial risk. A single misinterpreted command could delete critical data, disrupt services, or generate massive API costs. Implementing granular guardrails is a proactive cost-saving measure that limits blast radius and makes agentic workflows safer to deploy.
Understanding the Problem: AI Agent Permissions in M365
By default, Microsoft Graph permission scopes are often too broad for an AI agent's specific task. An agent granted 'Write' access could potentially delete or modify any resource it can see, creating significant risk. Lokka Guardrails acts as an additional policy layer on top of these scopes.
Key Controls Offered by Lokka Guardrails
The feature allows administrators to create rules that: 1) Allow or block specific HTTP methods (e.g., allow GET and POST, block DELETE and PATCH). 2) Restrict allowed Microsoft Graph API paths (e.g., only allow access to /users, not /groups). 3) Scope access to specific resources (e.g., only certain users, groups, or sites). 4) Apply these rules globally across your tenant or on a per-tenant basis.

Implementing and Testing the Workflow
1. **Enable Guardrails**: The feature is off by default in Lokka. Enable it in the server configuration to start defining rules. 2. **Start with Conservative Rules**: As suggested by the author, a safe starting point is to only allow GET and POST requests while disabling DELETE and PATCH methods. 3. **Define Path and Resource Scopes**: Further tighten rules by specifying which Graph API paths (e.g., /me/messages) and which specific resources (e.g., a particular SharePoint site) the agent can access. 4. **Monitor and Adjust**: Use the logging feature. When a request is blocked, the Guardrails interface explains which rule triggered it, helping you refine policies without guesswork.