# 📚 Nexus guide: guardrails

*Published 2025-12-05*

<h2><strong>What are guardrails?</strong></h2><p>Guardrails are security policies that control how AI assistants interact with tools and data. Guardrails provide nuanced rules that make AI systems safer and more predictable.</p><p>‍</p><h2><strong>Why guardrails matter</strong></h2><p>When AI assistants use tools, they need different constraints than human users:</p><ul><li>Content limits: An AI shouldn’t read 10GB files that would overwhelm its context</li><li>Semantic filtering: Block prompts trying to access sensitive data patterns</li><li>Behavioral rules: Prevent actions that make sense for humans but not for AI</li><li>Dynamic policies: Adjust permissions based on the conversation context</li></ul><p>‍</p><h2><strong>Types of guardrails</strong></h2><div data-rt-embed-type='true'><table style="border-collapse: collapse; width: 100%;">
  <thead>
    <tr>
      <th style="border: 1px solid #ccc; padding: 12px; background: #333; color: #fff;">
        Input
      </th>
      <th style="border: 1px solid #ccc; padding: 12px; background: #333; color: #fff;">
        Output
      </th>
      <th style="border: 1px solid #ccc; padding: 12px; background: #333; color: #fff;">
        Behavioral
      </th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="border: 1px solid #ccc; padding: 12px; vertical-align: top;">
        <strong>Control what goes into the AI system:</strong><br><br>
        • Domain filtering: Limit which websites can be accessed<br>
        • File type restrictions: Block binary files or specific formats<br>
        • Size limits: Cap file sizes and directory traversal depth<br>
        • Pattern matching: Detect and block sensitive data patterns
      </td>
      <td style="border: 1px solid #ccc; padding: 12px; vertical-align: top;">
        <strong>Control what comes out of tools:</strong><br><br>
        • Data sanitization: Remove sensitive information from responses<br>
        • Format enforcement: Ensure outputs match expected schemas<br>
        • Content filtering: Block inappropriate or harmful content<br>
        • Response limits: Prevent overwhelming the AI with data
      </td>
      <td style="border: 1px solid #ccc; padding: 12px; vertical-align: top;">
        <strong>Control how the AI uses tools:</strong><br><br>
        • Rate limiting: Prevent excessive API calls<br>
        • Sequence controls: Enforce proper tool usage order<br>
        • State validation: Ensure operations happen in valid states<br>
        • Audit requirements: Force logging of certain operations
      </td>
    </tr>
  </tbody>
</table></div><p>‍</p><h2>How to add safety constraints to tool operations&nbsp;</h2><p>1. Identify the MCP server and tool. First, you need to know:</p><ul><li>The MCP server ID (the server providing the tool)</li><li>The specific tool/operation name you want to constrain</li></ul><p>2. List available guardrail templates. This shows you all the constraint templates available for that specific tool, with descriptions of what each does:</p><pre></pre><p>3. Add a guardrail, once you know which template to use:</p><pre></pre><p>4. To manage existing guardrails:&nbsp;</p><ul><li>List guardrails: See all constraints on a specific tool or server</li><li>Remove guardrails: Remove constraints by their ID</li></ul><p>‍</p><h2>Templates to enforce data validation rules</h2><p>Guardrail templates provide pre-configured validation rules that you can apply to tool parameters and responses. Here are the common types:</p><p>Value constraints:</p><ul><li>min/max values: Enforce numeric ranges (e.g., budget must be ≤ $10,000)</li><li>min/max length: Control string/array sizes (e.g., descriptions must be ≤ 500 chars)</li><li>enum/allowed values: Whitelist specific values (e.g., status must be "draft", "active", or "paused")</li><li>blocked values: Blacklist certain values</li></ul><p>Pattern validation:</p><ul><li>regex patterns: Match specific formats (e.g., email addresses, phone numbers)</li><li>data type validation: Ensure correct types (string, number, boolean, etc.)</li></ul><p>Structural validation:</p><ul><li>required fields: Ensure certain parameters are always provided</li><li>schema path targeting: Apply rules to nested data structures using JSONPath</li></ul><p>‍</p><h2>Scope guardrails to specific servers or tools</h2><p>Guardrails use a hierarchical scoping system that lets you target constraints at different levels of specificity.</p><p>1. <strong>Server-level scope</strong> allows you to apply guardrails to an entire MCP server. It affects all tools within that server:</p><pre></pre><blockquote>Tip: When you omit <code>operationName</code>, the guardrail applies globally to all operations from that server.</blockquote><p>2. <strong>Tool-level scope</strong> <em>(most common) </em>allows you to apply guardrails to a specific tool/operation within a server. This targets just one tool, giving you fine-grained control:</p><pre></pre><p>3. <strong>Parameter-level scope</strong> allows you apply guardrails more precisely. Within a tool, you can target specific parameters or parts of a data structure using <code>schemaPath</code>. The JSONPath you put in <code>schemaPath</code> lets you drill down to the exact field you want to constrain:</p><pre></pre><p>‍</p><h2>List existing guardrails</h2><p>1. To list all guardrails for a server:</p><pre></pre><p>2. To list guardrails for a specific tool:</p><pre></pre><p>The list will show you:</p><ul><li>Constraint ID (you'll need this to remove it)</li><li>Template type being used</li><li>The constraint value</li><li>Schema path (if targeting specific parameters)</li><li>When it was added</li></ul><p>‍</p><h2>Remove guardrails</h2><pre></pre><p>‍</p><h2>Toolkit data hooks</h2><p>1. Pre-populate tool parameters automatically (<code>Hook_Parameter</code>)</p><p>Automatically set parameter values so the AI doesn't need to ask for them.</p><p>Use case: Always use a specific account ID, region, or configuration value.</p><pre></pre><p>2. Filter which tools are visible to the AI (<code>Hook_Filter</code>)</p><p>Hide tools from the AI to reduce noise or prevent access to certain operations.</p><p>Use case: Only show read operations, hide dangerous delete functions.</p><pre></pre><p>3. Create aliases or rename tools (<code>Hook_ Alias</code>)</p><p>Give tools friendlier or more descriptive names.</p><p>Use case: Rename technical tool names to business-friendly terms.</p><pre></pre><p>4. Clone tools with different configurations (<code>Hook_Clone</code>)</p><p>Duplicate a tool with a new name, allowing different parameter presets.</p><p>Use case: Create "production" and "staging" versions of the same tool.</p><pre></pre><p>5. Override or add to tool descriptions (<code>Hook_CustomDescription</code>)</p><p>Change how tools are described to the AI for better context.</p><p>Use case: Add business context, warnings, or usage guidelines.</p><pre></pre><p>‍</p><h2>Managing hooks&nbsp;</h2><p>1. Read existing hooks:</p><pre></pre><p>2. Describe hook structure and examples:</p><pre></pre><p>3. Delete hooks:</p><pre></pre>

Source: https://www.civic.com/news/guardrails
