+150 XP

ChatGPT · Guardrails: permissions, review, and cost

An agent that can send an email, merge a pull request, or move money is only as safe as the gates you put in front of those actions. The model is no longer just generating text. It is acting, and a confident hallucination becomes a real-world consequence. This lesson covers the control layer: what an agent may touch, when a human must approve, what should never run unsupervised, and how to stop a runaway loop from burning your budget.

The three failure modes you are guarding against

Every guardrail you build maps to one of these:

  1. Wrong action taken. The agent does something it shouldn't (deletes a record, emails the wrong client).
  2. Right action, wrong scope. The agent does the correct thing but with too much reach (refunds the whole order instead of one line item).
  3. Runaway cost. A loop, a retry storm, or a huge tool output that re-enters the context and spikes your token bill.

Permissions address #1 and #2. Human review catches the high-stakes edge of both. Cost controls handle #3. Treat these as separate systems, not one big "be careful" instruction.

Permissions: scope the tools, not the prompt

The single biggest mistake is putting safety in the prompt ("never delete anything without asking"). Prompts are suggestions. Permissions live in code and configuration, where the model cannot talk its way past them.

In ChatGPT (the product)

When you build with Custom GPTs and GPT Actions, you define exactly which API endpoints the action can hit via the OpenAPI schema. The GPT cannot call an endpoint you didn't expose. Use OAuth in the action's auth config so each user acts with their own permissions, not a shared key. See the Actions documentation for the auth flow.

Apps in ChatGPT (formerly called connectors: Google Drive, SharePoint, GitHub and others) inherit the connected account's permissions. If you connect a read-only service account, the agent gets read-only access. Provision the underlying account with least privilege before you connect it. On Business and Enterprise plans, admins can also restrict which apps are available and what actions they may take.

The ChatGPT agent browses, runs code, and uses apps in a sandboxed environment, and it pauses to ask before consequential steps like submitting a form or making a purchase. Treat that built-in confirmation as the floor, not your whole strategy.

In the API (where you control everything)

With the Responses API and the Agents SDK, permissions are code around your tool functions. The model proposes a call; your code decides whether to honor it.

python
ALLOWED_REFUND_CEILING = 100_00  # cents

def issue_refund(order_id: str, amount_cents: int) -> dict:
    if amount_cents > ALLOWED_REFUND_CEILING:
        return {
            "status": "needs_review",
            "reason": f"Amount {amount_cents} exceeds auto-approve ceiling",
        }
    result = payments.refund(order_id, amount_cents)
    return {"status": "done", "refund_id": result.id}

The model never sees the payment credentials and cannot raise the ceiling. The rule is enforced where it counts.

OpenAI now ships some of this tooling directly. The Agents SDK has input and output guardrails (checks that run alongside the agent and can halt a run) and supports marking tools as requiring human approval. AgentKit's visual Agent Builder includes guardrail and approval nodes, and the open-source Guardrails library covers common checks like PII detection and jailbreak screening. Use them, but keep hard limits like the refund ceiling in your own tool code.

The review gate: a concrete example

Here is the pattern in practice: an agent drafts an action, but a human approves it before it executes. This is a two-phase tool. Phase one returns a proposal. A human (or a separate approval step) confirms. Phase two commits.

Imagine a support agent that handles refund requests. You want it to do the tedious work (look up the order, read the policy, draft the refund) but never to move money on its own above a threshold.

python
PENDING = {}  # in production, use a real datastore

def propose_refund(order_id: str, amount_cents: int, reason: str) -> dict:
    token = f"refund_{order_id}"
    PENDING[token] = {"order_id": order_id, "amount_cents": amount_cents}
    return {
        "status": "awaiting_approval",
        "approval_token": token,
        "summary": f"Refund ${amount_cents/100:.2f} on {order_id}: {reason}",
    }

def commit_refund(approval_token: str) -> dict:
    job = PENDING.pop(approval_token, None)
    if not job:
        return {"status": "error", "reason": "unknown or already-used token"}
    receipt = payments.refund(job["order_id"], job["amount_cents"])
    return {"status": "done", "refund_id": receipt.id}

The agent can call propose_refund freely. commit_refund is never exposed to the model as a tool; your approval UI calls it after a human clicks approve. The model's job ends at "here is what I want to do." A person owns the "yes." (In production, generate a random token rather than one derived from the order ID.)

This is the mental model for every high-stakes automation: propose by AI, commit by human, with the commit step gated behind something the model can't forge. The Agents SDK's built-in tool approvals implement the same idea: the run pauses with a pending approval, and your code resumes it once a person decides.

Building Human-in-the-Loop AI Agents

Watch on YouTube

Where to put the human

Not every action deserves the same gate. Sort your tools into buckets:

  • Auto: read-only or trivially reversible (look up an order, draft text, search docs). No gate.
  • Review: consequential but routine (send a customer email, create a ticket, refund under a ceiling). Human approves, ideally in batch.
  • Never unsupervised: irreversible or high-blast-radius (delete production data, wire money above a limit, publish to all users, change permissions). Always a person, always logged.

Make these buckets explicit in your design doc. "Which bucket is this tool in?" is the first question for any new capability you add.

What to never automate unsupervised

A few categories belong in the third bucket no matter how good your agent is:

  • Irreversible deletions of customer or production data.
  • Outbound financial transactions above a small, fixed limit.
  • Identity and access changes (granting roles, rotating someone else's credentials, changing sharing settings).
  • Public or mass communication (posting publicly, emailing a whole list, anything that can't be unsent).
  • Legal or compliance commitments (signing, agreeing to terms, regulatory filings).

The test: *if the agent gets this wrong once, can I undo it before anyone is harmed?* If the answer is no, a human commits it. Scheduled tasks make this sharper, because a scheduled task in ChatGPT runs while you're not watching. Anything on a schedule should produce a draft or a notification, not fire an irreversible action into the void.

Knowledge check

1. Why does the lesson argue that putting safety rules in the prompt (e.g., 'never delete anything without asking') is the single biggest mistake?

2. An agent correctly issues a refund but refunds the entire order instead of the single line item requested. Which failure mode is this?

3. According to the lesson, how should you treat the ChatGPT agent's built-in confirmation before consequential steps?

MULTIPLE CHOICE

4. Select ALL correct statements about how permissions work with Custom GPTs, GPT Actions, and Connectors.

Select all the correct answers.

MULTIPLE CHOICE

5. Select ALL correct pairings of a guardrail system to the failure mode it primarily addresses.

Select all the correct answers.

Keeping cost in check

Agents loop. That is their power and their financial risk. A single misbehaving run can call a tool fifty times, re-feed each bloated result into the context, and quietly run up a bill far larger than a normal chat. Cost control is a guardrail, not an afterthought.

Cap the loop

The most important limit is the maximum number of steps an agent may take. In the Agents SDK, you set a turn limit so a stuck agent stops instead of spinning forever.

python
from agents import Agent, Runner

agent = Agent(name="support", instructions=SYSTEM_PROMPT, tools=[propose_refund])

result = Runner.run_sync(agent, "Refund order 8842, item was defective", max_turns=8)

If the agent can't finish in eight turns, it halts with an error you can catch and log. That single parameter is the difference between a bounded task and a runaway loop.

Control what re-enters the context

Token cost compounds because every tool result gets added to the context and re-sent on the next call. A 20,000-token API dump that the model only needed one field from will cost you on every subsequent turn. Truncate and summarize tool outputs before returning them.

python
def search_logs(query: str) -> dict:
    rows = db.search(query, limit=2000)
    return {"matched": len(rows), "top": rows[:5]}  # not all 2000

Return the count and a sample, not the whole haystack. The model rarely needs the raw dump, and your wallet definitely doesn't.

Right-size the model and use the cheap levers

You don't need your most capable model for every step. Routing classification and extraction to a smaller, cheaper model and reserving the frontier model for genuine reasoning is one of the highest-impact cost moves available. Reasoning models also let you set a lower reasoning effort for simple steps. Check the current lineup and per-token rates on the OpenAI pricing page, since the exact models and numbers shift over time.

Two more levers:

  • Prompt caching reduces the cost of the repeated, static part of your prompt (system instructions, tool definitions) when the same prefix recurs. Keep your stable content at the front so it caches.
  • Structured outputs keep responses tight and parseable, which avoids the re-prompt-and-retry cycles that quietly double your spend. Define the schema and the model returns exactly that shape.

Watch spend, don't discover it

Create separate projects (one for dev, one for prod) with their own API keys, so you can attribute spend and revoke the noisy one. Set a monthly budget and alert thresholds on each project in your OpenAI billing and project settings, and use project rate limits to cap how fast a bug can spend. Then watch the usage dashboard. A cost spike on a graph is an early warning; a surprise invoice is a postmortem.

Putting the layers together

A well-guarded agent has all three systems working at once:

  1. Permissions decide what tools exist and what scope each one has, enforced in code.
  2. Review gates sit in front of the consequential tools, with a propose-then-commit split so a human owns every irreversible "yes."
  3. Cost controls cap the loop, trim what re-enters the context, route to the right model, and alert on spend.

None of these lives in the prompt. The prompt shapes behavior; the guardrails enforce limits. When you add a new capability, ask in order: *What can this touch? Who approves it? What does it cost if it loops?*

Key Takeaways

  • Enforce permissions in code, not in the prompt. Use GPT Actions schemas, least-privilege accounts behind ChatGPT apps, and tool-level checks the model cannot override.
  • Use a propose-then-commit gate for high-stakes actions. The Agents SDK's tool approvals and AgentKit's guardrail nodes help, but hard limits belong in your own code.
  • Keep an explicit "never unsupervised" list: irreversible deletes, money above a fixed limit, access changes, mass communication, and legal commitments.
  • Cap every agent's step count with max_turns (or its equivalent), and truncate tool outputs so bloated results don't re-enter the context on every loop.
  • Separate dev and prod into projects with budgets and alerts, route cheap steps to cheaper models, and watch the usage dashboard so a spike is a warning, not an invoice.

What to do, from this lesson

These actions are compiled in the role's Playbook.

  • Use OAuth for user-scoped or write Actions; API keys only for shared read-only
  • Use propose-then-commit gates with tokens for all high-stakes actions
  • Set hard billing limits with separate API keys per environment
See the full action playbook →

Related articles

Recent articles from the blog that build on this lesson.