← Back to Learn
policy-enginebest-practicestutorial

YAML Policy Template for Data Analysis Agents

Authensor

Data analysis agents query databases, generate reports, and produce visualizations. They have broad read access to potentially sensitive data, making controls around what data they can access and how they can share it essential.

version: "1.0"
name: "data-analysis-policy"
description: "Policy for data analysis and reporting agents"

defaults:
  action: deny
  log: true
  notify: false

rules:
  # Allow read-only database queries
  - name: "allow-select-queries"
    match:
      tool: "database_query"
      parameters:
        query:
          pattern: "^SELECT"
          not_pattern: "(INTO OUTFILE|INTO DUMPFILE)"
    action: allow

  # Block write queries
  - name: "block-write-queries"
    match:
      tool: "database_query"
      parameters:
        query:
          pattern: "^(INSERT|UPDATE|DELETE|DROP|CREATE|ALTER|TRUNCATE)"
    action: deny

  # Allow querying analytics databases
  - name: "allow-analytics-db"
    match:
      tool: "database_query"
      parameters:
        database:
          in: ["analytics", "reporting", "warehouse"]
    action: allow

  # Block access to PII-containing tables
  - name: "block-pii-tables"
    match:
      tool: "database_query"
      parameters:
        query:
          pattern: "(users_personal|credit_cards|ssn_records|medical_records)"
    action: deny

  # Allow generating charts and visualizations
  - name: "allow-visualization"
    match:
      tool: "create_chart"
    action: allow

  # Allow writing reports to the reports directory
  - name: "allow-report-writes"
    match:
      tool: "write_file"
      parameters:
        path:
          pattern: "^/workspace/reports/"
          not_pattern: "\\.(sh|py|js|ts)$"
    action: allow

  # Require approval for data exports
  - name: "approve-data-export"
    match:
      tool: "export_data"
    action: approve
    approval:
      timeout: 600
      approvers: ["data-team-lead"]

  # Block external sharing
  - name: "block-external-share"
    match:
      tool:
        in: ["send_email", "upload_file", "http_request"]
    action: deny

  # Allow reading documentation
  - name: "allow-docs"
    match:
      tool: "read_file"
      parameters:
        path:
          pattern: "^/workspace/(docs|schemas)/"
    action: allow

Design principles for data analysis policies:

Read-only database access. Analysis agents have no business modifying production data. SELECT queries only, with explicit blocks on any write operations.

PII table exclusion. Tables containing personally identifiable information are blocked by name pattern. The agent can analyze aggregated data but cannot access individual records in sensitive tables.

Export controls. Generating reports within the system is allowed. Exporting data outside the system requires human approval. Sending data externally is blocked entirely.

Database scoping. The agent is restricted to analytics and reporting databases. Production operational databases are not accessible.

Monitor the denied queries to understand what data the agent attempts to access. If legitimate analysis needs are blocked, adjust the policy rather than removing the constraints.

Keep learning

Explore more guides on AI agent safety, prompt injection, and building secure systems.

View All Guides