Guardrails and cost control for your agentic workloads with Amazon Redshift

Post Syndicated from Jason Pedreza original https://aws.amazon.com/blogs/big-data/guardrails-and-cost-control-for-your-agentic-workloads-with-amazon-redshift/

Note (November 2026): This post covers both MCP servers because the Redshift MCP Server has Redshift-specific settings, such as read-only by default and a cap on result rows, that the AWS MCP Server doesn’t have yet. We’ll update this post when the AWS MCP Server reaches parity.

Guardrails and cost control matter more as AI agents handle an increasing share of the queries in your analytics environments. Asked “Why did revenue drop in the West region last weekend?”, an agent finds the tables, writes and runs the SQL on Amazon Redshift, and follows up. This is agentic analytics, on your data warehouse and lakehouse.

Two risks decide whether these agentic workloads reach production. The OWASP Top 10 for LLM Applications names both:

  • Excessive agency: The agent can do too much. An agent acts on what a model decides. With more tools or permissions than its task needs, a misread request or an instruction hidden in a support ticket can become a real action, such as exporting customer records.
  • Unbounded consumption: The agent can spend too much. A retry loop can rerun a heavy query all night. A query can return millions of rows that the agent then sends to the model as input tokens. Finally, one SQL query that runs Amazon Bedrock model inference through Redshift ML invokes the model once for every row it processes.

Redshift includes the controls for both at no additional charge: per-agent roles, row-level and column-level security, dynamic data masking, read-only tools, workload management, and usage limits. You pay for queries from agents as you do for queries from any other client: for the compute and storage they use (Amazon Redshift pricing). Your agent’s model provider bills its model tokens, for example at Amazon Bedrock pricing when the agent uses a model in Amazon Bedrock. You pay for the Amazon Bedrock, Amazon Bedrock AgentCore, and monitoring controls in this post at their own rates.

In this post, we show you how to add guardrails and cost controls to agentic analytics on Redshift, using one model: six guardrails, three enforcement layers, and one cost envelope.

The layered guardrail model

Each request passes through the agent layer, the access layer, and the data layer before it reaches your data warehouse or lakehouse, and the cost envelope limits spend across them.

The layered guardrail model for agentic analytics on Amazon Redshift, read top to bottom in four numbered rows. 1, agentic patterns: conversational analytics through AI assistants with MCP servers or apps with Knowledge Bases, Enrich with Redshift ML, Act with scoped tools behind AgentCore Gateway, and Operate with Kiro and Redshift skills. 2, the agent layer, mostly probabilistic, screens prompts and tickets, guides reasoning, and checks the answer. 3, the access layer, deterministic, keeps SQL tools read-only, blocks infrastructure changes, and scopes writes. 4, the data layer, prompt-independent, applies per-agent identity, row, column, and masking policies, output limits, and compute limits. One storage box holds Redshift managed storage, and Apache Iceberg in Amazon S3 and S3 Tables with Lake Formation permissions. Below, the cost envelope adds model tokens, query compute, and data at rest, with no new meter.

Figure 1: The layered guardrail model. The lower the layer, the less a prompt can change it

Each guardrail type controls one thing and maps to an OWASP risk. Each layer is who enforces it:

  • Agent layer: Your agent or application, its framework, and Amazon Bedrock.
  • Access layer: The tools between the agent and your data, such as MCP servers and AgentCore Gateway (a capability of Amazon Bedrock AgentCore), and the IAM policies on the identities those tools use.
  • Data layer: Amazon Redshift and, for lakehouse tables, AWS Lake Formation.

The following table lists the six guardrail types. Each row names the guardrail type, the main OWASP risk it reduces, and the layer and controls that enforce it.

Guardrail type Main risk (OWASP) Who enforces it
Input Prompt injection (LLM01) Agent layer: Bedrock Guardrails, input validation
Reasoning and planning Excessive agency (LLM06) Agent layer: skills, business context, tool allow lists, step limits
Tool and action Excessive agency (LLM06) Access layer: tools, IAM, Policy in Amazon Bedrock AgentCore, threshold approval
Data Sensitive information disclosure (LLM02) Data layer: privileges, row and column policies, masking
Output Sensitive information disclosure (LLM02), Improper output handling (LLM05) Data layer. Agent layer for answers
Runtime and cost Unbounded consumption (LLM10) Data layer limits, token caps, AWS Budgets

The agent layer is the first filter, but it cannot be the only one. Most Amazon Bedrock Guardrails checks are model-based classifiers, some with a strength that you tune, so they catch most problems but not all. The guardrails that protect your data in Redshift therefore sit in the access and data layers, which apply fixed rules to the caller’s identity. You need both. AWS Identity and Access Management (IAM) policies decide which Redshift workgroups and APIs it can call, and Redshift and Lake Formation permissions decide what its SQL can touch. Fixed rules give the same answer whichever agent wrote the request, so a prompt injection that gets past the agent layer still cannot reach data that the agent’s identity is not granted.

Agentic analytics patterns on Amazon Redshift

Conversational analytics, the most common pattern, answers business questions from your data in self-service and managed delivery models. The others enrich data, take actions, or help administrators run the warehouse itself.

Pattern How it connects to Redshift Starting agency
Conversational analytics, self-service AI assistants (agents that a person works with directly) such as Kiro, Amazon Quick, and the Amazon SageMaker Data Agent, through the AWS MCP Server or Amazon Redshift MCP Server over the Redshift Data API Read-only
Conversational analytics, managed Amazon Bedrock Knowledge Bases turns end users’ questions into SQL Read-only
Enrich Redshift ML with Amazon Bedrock calls a model from SQL None: the model returns a column value
Act One scoped tool per action Scoped writes. Human approval for consequential ones
Operate Administrators review and tune the warehouse with Kiro, Redshift skills, and the MCP Server review_cluster tool Read-only. Changes ship as reviewed code

Every pattern needs the same two scopes for least privilege: IAM permissions that limit which workgroups and APIs an identity can call, and database permissions that limit what its SQL can read or change. What differs is which identity reaches Redshift:

  • Self-service (AI assistants with the Redshift MCP Server or AWS MCP Server). The AI assistant acts on behalf of the user, with the AWS profile in its MCP configuration. If your roles have different scopes, set up a profile for each and point the server at the narrowest one for the task, such as a read-only analyst role for sales questions. The setup steps are in access-layer/redshift-mcp-server and access-layer/aws-mcp-server in the aws-samples repository.
    • Redshift MCP Server: A user whose profile assumes a DataPlatformAdmin role runs every agent query as IAMR:DataPlatformAdmin, with that role’s grants. The server is read-only by default, and the agent can’t switch profiles. To use a broader profile, change it yourself in the MCP configuration.
    • AWS MCP Server: The agent can switch on each call among the profiles listed in the MCP Proxy for AWS configuration. List only the profiles you want it to use, and put the read-only one first so it’s the default. On provisioned clusters, a script can also choose a database user if the role allows redshift:GetClusterCredentials, so leave that permission out.
    • Both: The MCP configuration only controls the MCP tools. An agent that can run shell commands can use any profile on the machine, so the IAM roles and database grants are the real boundary.
    • SageMaker Data Agent: The agent runs SQL itself, including cells it fixes, as the signed-in person. Without trusted identity propagation, Redshift sees one IAMR:user-<id>@<project> database user per project member. With it, Redshift sees the person’s AWS IAM Identity Center user, so row-level security, masking, and grants apply to each person.
  • Custom agents, for example on Amazon Bedrock AgentCore. The database user comes from the role that calls the Data API: the AgentCore Runtime execution role, or the AWS Lambda function’s role behind AgentCore Gateway, such as IAMR:agent-support. If the agent acts for a specific person, use trusted identity propagation. The agent’s tool exchanges the person’s sign-in token through AWS IAM Identity Center, optionally federated with your external identity provider, and calls the Data API as that person. Redshift then applies their grants (writes included), row-level security, and masking, plus Lake Formation permissions if you enable that integration.
  • Managed (Amazon Bedrock Knowledge Bases). The knowledge base runs the SQL it generates as one identity. On Serverless workgroups and provisioned clusters, that is its service role with IAM or the user in an AWS Secrets Manager secret. Provisioned clusters also accept a named database user (authentication methods). Knowledge Bases can’t carry the actual user with trusted identity propagation, so when one identity serves many end users, row-level security can’t tell them apart. With one shared knowledge base, a West region manager and an East region manager query as the same database user, so both get every row that user can read. Instead, create one knowledge base or agent for each audience, such as one per sales region, and scope its role, grants, and row-level security policy to that audience.
Three access paths and the identity Amazon Redshift sees on each. A self-service AI assistant with the Redshift MCP Server or AWS MCP Server acts with the user’s AWS profile, so its queries run as a database user such as IAMR:DataPlatformAdmin. A custom agent in AgentCore Runtime, or a Lambda tool behind AgentCore Gateway, uses its execution role, such as IAMR:agent-support. Bedrock Knowledge Bases uses one identity for all its end users: its service role, a database user on provisioned clusters, or a Secrets Manager user, so row-level security can’t tell those users apart. Every path needs an IAM policy and database permissions. A band says one identity per agent gives it its own policies, cost, and audit.

Figure 2: Who Redshift sees on each access path

Decide how much agency to grant

Grant agency, what an agent can do, on two planes. The data plane is SQL on Redshift managed storage or Apache Iceberg tables, governed by Redshift and AWS Lake Formation permissions. The control plane is API calls that create, resize, manage, or delete infrastructure, governed only by IAM. The AWS Agentic AI Security Scoping Matrix bounds agency with permissions and autonomy with oversight. Following it, start read-only (Scope 1), then add scoped writes with a human in the loop for consequential ones (Scope 2). Keep agents off the control plane, and widen autonomy (Scopes 3 and 4) only within those boundaries.

Agent layer: Guide the request

The agent layer, mostly outside Redshift, is the first filter. Its controls run in your agent, Amazon Bedrock, and Amazon Bedrock AgentCore, so you set them up and pay for them there. These include the step, retry, and token limits that cap the agent’s own model spend.

  • Input. Bedrock Guardrails filters prompt injection attempts and denied topics, and ApplyGuardrail works with your choice of model.
  • Skills. The redshift-guide skill gives agents Redshift-specific knowledge, so fewer queries fail. The Agent Toolkit for AWS (aws configure agent-toolkit, AWS Command Line Interface (AWS CLI) 2.35.0 or later) and the AWS Data Analytics Plugin deliver skills to Kiro and other AI assistants.
  • Business context. Business context and skill assets in the AWS Glue Data Catalog tell agents which tables and joins to use. They are in preview in the US East (N. Virginia), US East (Ohio), US West (Oregon), and Europe (Ireland) Regions.
  • Agent configuration and oversight. Limit an agent’s tools before it runs. In Kiro, for example, the MCP configuration lists the tools to approve automatically (autoApprove) and the tools to hide from the agent (disabledTools). Add project instructions, and set step and retry limits in agent frameworks.

Access layer: Limit what the agent can call

The access layer decides which tools an agent can call and what each call can do. Redshift enforces its guardrails the same way for every prompt.

Data plane: A narrow tool surface on every path

Figure 3 shows the tool guardrail each connection path needs, plus least-privilege IAM and database permissions. Each path has a worked example in the access-layer folder of the aws-samples repository, with setup, verification, and clean-up steps.

Four access paths, each with what the agent can send, its guardrail, and how it connects. Redshift MCP Server: any SQL. Read-only mode: nothing a query changes is kept. One Data API call per tool call. AWS MCP Server: Python in aws___run_script. An agent profile and IAM policies on aws:ViaAWSMCPService. One Data API call per statement. Custom MCP server: only tool parameters. Fixed SQL and validated parameters, with AgentCore Policy checking each call at AgentCore Gateway. Bedrock Knowledge Bases: questions turned into SQL. One database and up to 50 tables, with descriptions and example queries steering the SQL. One session per Retrieve call. A band adds CONNECTION LIMIT and statement_timeout on every path, and SESSION TIMEOUT for idle driver sessions.

Figure 3: Access paths and their guardrails

Agents with shell access can bypass an MCP server with the AWS CLI, so scope IAM on every path. To allow only the AWS MCP Server path, see AWS MCP Server only, later in this section.

The agent’s IAM policy, access-layer/shared/agent-data-plane-policy.json in the aws-samples repository, has three statements:

  • Discover lets the agent list workgroups. It uses "Resource": "*" because ListWorkgroups doesn’t support resource-level permissions, so it can’t limit where SQL runs.
  • RunSqlOnOneWorkgroup lets the agent sign in and run SQL on one workgroup only. This is the statement that limits where SQL runs. It includes redshift-data:BatchExecuteStatement, which the Redshift MCP Server needs before it can run writes or named transactions. Without that action, the server stays read-only by refusing writes itself. With it, writes still need ACCESS_MODE=read-write in the MCP configuration, which is off by default, and the agent’s database grants still limit what a write can change.
  • ReadOwnStatements lets the agent check status and read results only for statements it ran itself.

Custom MCP server: Tools that run fixed SQL. Expose only tools that each run one fixed, parameterized statement against a curated view, under the server’s own IAM role with SELECT on that view only. Have each tool set a fixed StatementName and SQL comment, so AWS CloudTrail and query history name the tool. In the sample server (access-layer/custom-mcp-server/sales_metrics_mcp.py), the agent supplies only a sales region, which the server checks against an allowed list, so prompt injection can at most make the tool query a different allowed region.

AWS MCP Server: Scope the credentials, not the script. Its aws___run_script sends SQL through the Data API as the caller’s mapped database user, so an administrator profile means administrator access. Four guardrails close that gap:

  • A dedicated agent profile in the MCP Proxy for AWS, for an agent role with read-only grants.
  • No way to switch database users. Allow redshift-serverless:GetCredentials or redshift:GetClusterCredentialsWithIAM, not redshift:GetClusterCredentials or Secrets Manager secrets, which let a caller choose another user.
  • Agent workgroups only. A service control policy in AWS Organizations denies Data API SQL through AWS managed MCP servers unless the workgroup is tagged agent-access=true. The same statement also works in an IAM policy or permissions boundary. SCPs skip the management account, so test on a sandbox OU first:
{
  "Sid": "AgentsQueryOnlyAgentWorkgroups",
  "Effect": "Deny",
  "Action": ["redshift-data:ExecuteStatement", "redshift-data:BatchExecuteStatement"],
  "Resource": "*",
  "Condition": {
    "Bool": { "aws:ViaAWSMCPService": "true" },
    "StringNotEquals": { "aws:ResourceTag/agent-access": "true" }
  }
}
  • AWS MCP Server only. To stop the agent’s shell from going around the server, deny redshift-data:* on the agent role unless the call comes through it. Also deny direct driver sign-in when aws:ViaAWSService is false: redshift-serverless:GetCredentials, redshift:GetClusterCredentialsWithIAM and redshift:GetClusterCredentials, plus GetIdentityCenterAuthToken when you use trusted identity propagation (access-layer/aws-mcp-server/deny-data-api-outside-aws-mcp.json). Attach it to agent roles or permission sets, not as an SCP. IAM can’t tell the local Redshift MCP Server from the AWS CLI, so on that path read-only database grants are the boundary:
{
  "Sid": "DataApiOnlyThroughAwsMcp",
  "Effect": "Deny",
  "Action": "redshift-data:*",
  "Resource": "*",
  "Condition": { "BoolIfExists": { "aws:ViaAWSMCPService": "false" } }
}

Bedrock Knowledge Bases: One database, listed tables, read-only grants. Inclusions (up to 50 tables) and exclusions narrow the generated SQL but aren’t a substitute for guardrails. A timeout of up to 200 seconds (60 in access-layer/bedrock-knowledge-base/kb-redshift-config.json) cancels the query. Scope the service role to one workgroup (and redshift-serverless:GetCredentials on Amazon Redshift Serverless) with SELECT on included tables only. Allow DescribeStatement, GetStatementResult, and CancelStatement on its own statements only. The sync fails without CancelStatement (access-layer/bedrock-knowledge-base/kb-service-role-policy.json).

Scope every write, and keep a human in the loop where it matters

Give an agent one scoped tool per action, never a generic write tool. A write can run on its own when its tool limits it to one validated, low-impact action, so approvals don’t slow routine work. Consequential, irreversible, or above-threshold writes need a human in the loop:

Mechanism How it works Can the agent bypass it?
Approve as data (recommended for data writes) The tool records a request. A people-only identity approves it No: Redshift enforces it
Approve in the agent The framework asks a person first Depends on the framework
Approve as code review Schema and infrastructure changes ship as reviewed code No: your pipeline enforces it

In the Act pattern, an agent writes to Redshift as part of a workflow, such as issuing a refund. Figure 4 shows how it combines both kinds of write:

  1. The agent’s only write tool, refund_order, runs as an identity that can only EXECUTE one procedure.
  2. The SECURITY DEFINER procedure checks the order and caps the amount at the remaining refundable amount and $500, locking support.refunds against concurrent over-refunds. A failed check writes nothing and returns an error the agent can report.
  3. Refunds up to $100 are approved. Larger ones wait for the refund_approvers role, through a second procedure that rejects self-approval.
  4. A payment process pays approved refunds only.
The Act pattern in four numbered steps. A support agent calls 1, the refund_order tool, which runs as an action identity that can call one procedure and read no tables. 2, the support.refund_order procedure in Redshift, checks the order and caps the amount at what is left and $500. Refunds up to $100 are approved, refunds from $100 to $500 wait for approval, and larger ones are rejected with an error and nothing written. 3, approve_refund, can be run only by refund_approvers, records the approver, and rejects self-approval. 4, the payment process, pays approved refunds only. A band explains that the agent’s identity has no table privileges, so it can’t go around the procedure.

Figure 4: A scoped action tool, with human approval above a threshold

The procedures and grants are in act-refund/refund_procedures.sql. Expose refund_order as its own tool, under an identity separate from the agent’s read path, so the read identity has no write privileges. Scheduled writes that no agent starts, such as a nightly Enrich job that labels tickets with Redshift ML, need a different control. Review the job’s SQL once before you deploy it, then run it under its own identity that no agent can use.

Control plane: Keep infrastructure changes out of agents’ reach

Control plane calls skip database grants, so IAM is the only gate, and an AI assistant’s credentials often reach its shell and the AWS CLI too.

Give every AI assistant a scoped identity. Run Kiro and other AI assistants, and their MCP servers, under an agent-role AWS profile with read-only control plane actions and a permissions boundary. Don’t allow redshift:Get*, which includes GetClusterCredentials. Share the profile through one AWS IAM Identity Center permission set (access-layer/shared/aws-config-example.ini). Role chaining caps sessions at 1 hour.

Deny infrastructure changes through managed MCP servers. With the aws:ViaAWSMCPService condition key, a service control policy can deny create, delete, modify, resize, pause, resume, reboot, restore, and tagging actions made through an agent but not directly (access-layer/shared/deny-infra-changes-through-agents.json). Tagging matters because the data plane deny trusts the agent-access tag.

Data layer: Decide what the agent can reach

The data layer decides what an agent can actually reach, on every query. As the Redshift MCP Server documentation puts it, “The database user’s privileges are the security boundary, not this server.”

Give every agent its own identity: One IAM role, database user, and database role. The IAM role agent-support signs in through the Data API as IAMR:agent-support. On Redshift Serverless, a RedshiftDbRoles tag can grant its database role at sign-in (the aws-samples repository shows the tag). Agents acting for a person can use trusted identity propagation. Grant the role after the user’s first sign-in:

-- One database role per agent: privileges go to the role, never to the user
CREATE ROLE agent_support;
GRANT USAGE ON SCHEMA sales TO ROLE agent_support;
GRANT SELECT ON sales.orders, sales.payments TO ROLE agent_support;
GRANT ROLE agent_support TO "IAMR:agent-support";

Then narrow what it sees (data-layer/fine-grained-access.sql):

  • Row-level security (RLS) filters rows only on tables you attach it to and makes a table default-deny, so attach policies for other roles first.
  • Column privileges remove columns, such as email.
  • Dynamic data masking transforms values, such as a card’s last four digits.

Limit what agents can discover. Turn on metadata security so catalog views and SHOW list only objects the role can access, so agents cannot plan around hidden tables (superusers and ACCESS CATALOG roles see all). Test on non-production first:

ALTER SYSTEM SET metadata_security = true; -- superuser only; applies to the whole cluster or workgroup
GRANT ACCESS CATALOG TO ROLE agent_monitoring; -- a monitoring role that must still see every object

Extend the rules to the lakehouse and other warehouses, so no path skips your filters. Redshift enforces Lake Formation permissions on Iceberg tables, including Amazon S3 Tables (a capability of Amazon S3), and federated permissions carry RLS and masking to an agent warehouse. Plain datashares do not carry RLS filters.

Treat free text as untrusted: Keep Redshift ML instructions in the static PROMPT prefix, and pass row text only as input.

Allow only approved models. The model’s IAM role decides at inference time, so allow bedrock:InvokeModel only on approved model ARNs. By default only superusers can create models. Grant CREATE MODEL to an ML platform role, with ASSUMEROLE ... FOR CREATE MODEL only on approved IAM roles.

Audit each agent’s reach with HAS_TABLE_PRIVILEGE (observe/detection/agent-table-privileges.sql). Until you revoke the default PUBLIC ASSUMEROLE grant, assume every user can use every IAM role attached to the warehouse. The AWS Identity and Access Management Access Analyzer (IAM Access Analyzer) check-access-not-granted check can fail deployments that grant redshift:GetClusterCredentials.

Test as the agent: Superusers and sys:secadmin bypass RLS.

Output guardrails: What the agent sees, keeps, and says

An agent has three outputs: results it reads, copies it keeps, and its answer. Redshift controls what enters the agent and its database-side copies. The application and agent layer govern the rest.

What the agent sees and says

The data layer’s policies double as output guardrails: results hold only permitted rows and readable columns, masked values stay masked, and Lake Formation filters do the same for Iceberg tables.

The sensitive information filtering in Bedrock Guardrails doesn’t inspect toolResult content, so mask in Redshift.

Cap result size too: provisioned clusters can abort on return_row_count, and the Redshift MCP Server’s MAX_RESULT_ROWS (1,000 by default) refuses larger results, protecting the context window, not compute.

Data-layer controls end when results leave Redshift, so check the answer too: Bedrock Guardrails can mask PII and flag ungrounded answers, and the generated SQL makes the answer traceable.

What the agent keeps: Database-side exports and copies

A copy starts with none of the source table’s policies, so treat every database-side write path as an output path:

Export path Guardrail
UNLOAD to Amazon S3 REVOKE ASSUMEROLE ON ALL FROM PUBLIC FOR ALL (which also blocks COPY and CREATE MODEL). Grant ASSUMEROLE ... FOR UNLOAD to pipeline roles only
CETAS and INSERT into external tables Agent roles own no external schemas
Writes to Apache Iceberg tables No Lake Formation write permissions for agent-facing roles
CTAS, SELECT INTO, and INSERT ... SELECT REVOKE CREATE ON SCHEMA public FROM PUBLIC. No CREATE or INSERT for agents
Datashares No datashare privileges for agent roles

The MCP Server’s read-only mode denies UNLOAD and CALL, but other paths bypass it, so privileges are the durable line (data-layer/exports-and-copies.sql). Audit exports in SYS_UNLOAD_HISTORY, SYS_QUERY_HISTORY, and CloudTrail S3 data events.

Figure 5 summarizes which layer controls each output.

Grid of output guardrails by layer for what the agent sees, keeps, and says. Agent layer: optional ApplyGuardrail screening of retrieved text, retained results governed by your application, and Bedrock Guardrails checks on the answer with the SQL kept. Access layer: the MCP Server MAX_RESULT_ROWS cap, and read-only mode that denies UNLOAD and CALL, with one approved write tool and approval above a threshold. Data layer: row-level security, column privileges, masking, and Lake Formation filters, plus ASSUMEROLE scoped for UNLOAD, s3:PutObject only to approved buckets, and no write or datashare privileges for agent roles. Data layer controls end when the result leaves Redshift.

Figure 5: What the agent sees, keeps, and says, and which layer controls each

The cost envelope: Predictable by design

Each agent question has three cost parts (Figure 1): model tokens at Bedrock rates, query compute on Redshift provisioned clusters or Amazon Redshift Serverless RPUs that you already pay for (older RA3 and DC2 clusters also bill lakehouse scans per terabyte), and data at rest. These compute guardrails are part of Redshift, and you pay only for the Redshift compute your queries use:

Guardrail Provisioned Serverless
Separate lane for agents WLM queues by user role Queues by user role, or a dedicated workgroup
Stop a runaway query Query monitoring rules that log, hop, or abort Workgroup query limits or queue rules that log or abort
Cap each statement statement_timeout per agent user Same as provisioned
Cap connections CONNECTION LIMIT and SESSION TIMEOUT per agent user Same as provisioned
Cap capacity Fixed node count. Concurrency scaling limits Max capacity in RPUs
Cap spend per period Concurrency scaling and Spectrum limits RPU-hour limits per day, week, or month

Set three ceilings on day one (Figure 6): a per-statement timeout for each agent user, max capacity on the agent workgroup, and a daily usage limit. Queue rules are checked every 10 seconds, so the timeout is the tighter cap.

Nested boxes showing the cost envelope, from outer to inner: per account (AWS Budgets alerts and AWS Cost Anomaly Detection), per Bedrock principal (cost by IAM principal in CUR 2.0 with activated agent tags, and a budget action that denies the agent’s Bedrock calls), per period (usage limits on RPU-hours), per workload (a dedicated workgroup or queue with max capacity), per query (query limits and statement_timeout), and per LLM call (a trusted tool fixes maxTokens, input size, and row count. Approved models only). The outer two act on billing data and the inner ones in real time. A band lists the three ceilings to set on day one.

Figure 6: The cost envelope. Each ceiling catches what the one inside it misses

Max capacity and the usage limit do different jobs (see Billing for on-demand compute capacity). Max capacity caps RPUs. The usage limit logs, alerts, or stops user queries once the period’s RPU-hours are used (cost-envelope/serverless-ceilings.sh). emit-metric only publishes a metric. Alarm on it, or choose Alert on the AWS Management Console.

Each Serverless workgroup or RG cluster accepts at most 2,000 connections. In our tests, Data API tools opened one connection per call, but an idle open driver transaction kept Serverless compute running until the 1-hour timeout. On Serverless, deny redshift-serverless:GetCredentials when aws:ViaAWSService is false. In our tests, this blocked driver sign-in, not direct Data API calls. On each non-superuser agent user (superusers ignore connection limits), set:

ALTER USER "IAMR:agent-support" SET statement_timeout TO 120000;
ALTER USER "IAMR:agent-support" CONNECTION LIMIT 10 SESSION TIMEOUT 300; -- size the limit to the agent's concurrency

Spend less per answer

  • Reuse work: The result cache, composition for new queries, and materialized views for repeated joins.
  • Right-size the engine. For lake-heavy agents, RG instances cost 30% less per vCPU than RA3, with no per-terabyte scanning charges.
  • Spend and store less. Every byte saved is a byte agents don’t read. For local tables, keep ENCODE AUTO so Redshift selects optimal column compression by data type. Iceberg tables use zstd compression by default, helping reduce storage and scan costs (cost-envelope/storage-compression.sql).

Control model spend per agent

Bedrock attributes inference cost to the calling IAM principal (Introducing granular cost attribution for Amazon Bedrock). Since Redshift ML calls Bedrock with the role in CREATE EXTERNAL MODEL, give each agent its own role. A trusted tool, the only identity allowed to run the model, fixes maxTokens and bounds input (cost-envelope/model-spend-summarizer.sql), and a budget action can deny bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream to the role as a period-level brake, not a real-time stop.

Per-agent users make SYS_QUERY_HISTORY a compute ledger. Tag both ledgers per AGENTCOST05-BP01. Because the Redshift MCP Server in read-only mode refuses SET query_group, attribute by IAM role.

Observe and prove

Security reviewers ask what the agent did, and FinOps reviewers ask what it cost. Per-agent identity answers both.

Figure 7 shows how the following records feed back into tighter guardrails.

A closed loop of five numbered steps. 1, Attribute: agent-* names for agent identities plus listed exceptions, self-reported application names for tracking only, and an estimated cost on a shared workgroup. 2, Audit: SYS_QUERY_HISTORY for what ran, CloudTrail for who and when, and AgentCore and Bedrock logs joined on role and time. 3, Retain: system tables kept in S3 Tables past 7 days, to profile agents across model changes. 4, Review: run as a monitoring identity with sys:monitor, audit IGNORE RLS and tag-granted roles, and alarm on shadow agents and loops. 5, Tighten: give a shadow agent its own identity or block it, stop loops with step and retry limits, and narrow grants and ceilings.

Figure 7: The observe and prove loop

What ran, and who called it. SYS_QUERY_HISTORY lists each agent user’s queries, and an agent- prefix on every agent identity lets one filter cover them. CloudTrail adds who and when. With trusted identity propagation, both identify the person.

Which client ran it. SYS_CONNECTION_LOG records each session’s self-reported application name, which we use for tracking, not as a control. CloudTrail records a shared role’s session name and SourceIdentity, which name a person only when your identity provider sets them or a trust policy condition key requires them (observe/attribution/queries-per-client.sql).

Find shadow agents, which are MCP calls from an identity without the agent- prefix. The application_name setting and the CloudTrail userAgent or userIdentity.invokedBy fields mark MCP traffic (observe/detection/shadow-agents.sql).

Keep a long-term record: System table integration with Amazon S3 Tables keeps system views, normally held 7 days, in read-only Iceberg tables as long as you set. Protect Bedrock invocation logs, which hold unmasked input, with Amazon CloudWatch Logs data protection.

Catch runaway loops with a scheduled check for repeated query shapes and errors (observe/detection/runaway-loops.sql).

Conclusion

In this post, we showed how the layered guardrail model runs agentic analytics on Amazon Redshift, with most controls built into Redshift. The access layer keeps a human in the loop for consequential writes, and the data layer decides what each query can reach.

To get started:

  1. Connect safely. Run the Amazon Redshift MCP Server read-only with a per-agent IAM role, and install redshift-guide from the Agent Toolkit for AWS.
  2. Bound the data. Grant only needed tables and columns, attach RLS and masking, revoke ASSUMEROLE and CREATE from PUBLIC, and test metadata security on non-production first.
  3. Bound the spend. Set a statement timeout, max capacity, and a daily usage limit, and test that the usage-limit alarm fires.

To go further, read Query Amazon Redshift using natural language with Kiro and Integrate Amazon Bedrock with Amazon Redshift ML. The complete SQL and CLI samples from this post are in the aws-samples repository. The repository README lists the prerequisites and the clean-up steps for what the samples create. Leave questions or feedback in the comments.


About the authors

Jason Pedreza

Jason Pedreza

Jason is a Senior Analytics Specialist Solutions Architect at AWS, where he helps customers architect petabyte-scale data platforms for AI-driven analytics. He focuses on modern lakehouse design, large-scale data migrations, and building the data foundations that power ML and generative AI applications.

Dan Jin

Dan Jin

Dan is a Sr. Analytics Specialist Solutions Architect at AWS based out of the San Francisco Bay Area. With over 20 years of experience in database and data analytics products, he has deep expertise in data system architecture and technical solution design. He focuses on helping customers modernize their data warehouses on Amazon Redshift and adopt AI-driven analytics.