Rubric
Contents — domains, guide and mocks

Guardrails and safe deployment

CCDV-F 7.214 min read · checked 21 September 2026

Task statementGuardrails and Safe Deployment (2.3%) — content policy, guardrail layering, and secure-by-design principles including privacy, identity and access management, and least privilege

Guardrails in series around one request

  1. Input guardrailscreen and classify before the call
  2. Constrained promptpolicy, scope, refusal text
  3. Modelproduces text and tool requests
  4. Output guardrailvalidate and screen the reply
  5. Action controlleast privilege, approval, audit log

every layer logged — monitoring closes the loop

Controls sit either side of the model and around its actions. The model's own judgement is one contributor, never the enforcement point.

Content policy: write it down before you enforce it

A content policy is a written list of what your application will not accept or produce, with each category defined well enough that two reviewers would agree. The documented approach to moderation starts here, not with a prompt: enumerate the unsafe categories, then add the definitions and context that make them decidable for your domain — what counts as financial advice on your platform, what counts as harassment in your community.

The moderator itself is then a small, cheap classifier: a fast model, the message wrapped in tags, the categories supplied, and a structured JSON verdict. The guide is explicit that a fast model is the right choice here, and gives the order-of-magnitude cost difference at scale as the reason.

A moderation call with graded outcomespython
PROMPT = """Determine whether this message warrants moderation,
using only the categories below.
<message>{message}</message>
<categories>{categories}</categories>
Return risk 0 (none), 1 (low), 2 (medium) or 3 (high)."""

def moderate(message: str) -> dict:
    r = client.messages.create(
        model=FAST_MODEL, max_tokens=256,
        messages=[{"role": "user",
                   "content": PROMPT.format(message=message, categories=CATS)}],
        output_config={"format": {"type": "json_schema", "schema": SCHEMA}},
    )
    return json.loads(r.content[0].text)

verdict = moderate(text)          # {"risk": 2, "categories": [...], "why": "..."}
if verdict["risk"] == 3:  block(text)            # auto-block
elif verdict["risk"] == 2: queue_for_human(text) # human review
elif verdict["risk"] == 1: warn_user(verdict)    # feedback, allow

Graded risk levels are worth more than a boolean. A binary flag forces one threshold to serve two different mistakes: blocking something harmless, and letting something harmful through. Levels let you auto-block only what you are confident about, send the ambiguous middle to a person, and give feedback on the rest — and they give you something to tune when you measure precision and recall on real traffic.

Layering: what each layer can and cannot catch

Guardrails divide neatly into two families, and a good design uses both. Deterministic controls — schema validation, allowlists, regular expressions, permission checks, rate limits — are cheap, fast and certain, but only catch what you can specify in advance. Model-based controls — a classifier screening input, a reviewer screening output — catch meaning rather than strings, but they are probabilistic and cost a call. Put the deterministic ones first: there is no sense paying a model to notice that a field is missing.

LayerCatchesMisses
Input classifierHarmful or manipulative requests, injection attemptsNovel phrasings; anything arriving later via tools
System prompt policyOrdinary drift; sets refusal behaviourA determined attacker; it is guidance, not enforcement
Schema validation of outputMalformed or out-of-range resultsWell-formed answers that are simply wrong
Output classifierLeaked secrets, policy-breaking contentSubtle errors; adds latency to every reply
Permission and scope checksActions the caller may not take, whatever the model askedNothing in this row — this is the enforcement layer
Human approvalAnything irreversible or high-valueVolume; people cannot review everything

Secure by design: least privilege and identity

Secure by design means the safe configuration is the default one, so a mistake produces a refusal rather than an incident. Claude Code is a useful worked example because its model is documented in detail: in its manual mode it starts read-only and asks before editing files or running commands that modify the system, while a built-in set of read-only commands runs without a prompt. Writes are confined to the directory it was started in and its subdirectories. Bash commands can be sandboxed with filesystem and network isolation. First use of a codebase or a new MCP server requires trust verification, and organisations can impose managed settings that a user cannot override.

Two ways to give an agent access

Convenient

  • One credential with broad rights, shared by all features
  • Every tool available on every request
  • Writes anywhere on the filesystem
  • Approval prompts disabled because they were annoying
  • Actions logged only when they fail

Least privilege

  • A scoped credential per tool, read-only where possible
  • Only the tools this task needs, attached per session
  • A working directory boundary, sandboxed execution
  • Human approval on irreversible or high-value actions
  • Every tool call logged with the caller's identity
Both agents can do the day-to-day work. Only one of them still does something small when an injected instruction arrives.

Identity and access management is the same discipline you would apply to any service, with one extra rule: the agent acts for a person, so it must act as that person. The identity comes from the authenticated session and is passed to the tool layer by your code; it is never an argument the model fills in. An agent that holds its own super-user credential has, in effect, granted every user the union of everyone's permissions.

Privacy belongs in the same design pass rather than in a later review. Minimise what enters the context, redact identifiers the task does not need, choose the retention posture your obligations require, and keep an audit trail of who asked for what. Those choices are cheap before launch and expensive afterwards; the detail of retention options and PII handling is in 7.1, and credential mechanics are 7.4.

A pre-deployment guardrail review

  • Passes: Written content policy with defined categoriesDecidable by two reviewers, not just by the model
  • Passes: Input screening before the main callFast model, structured verdict
  • Passes: Output validated against a schema before useDeterministic and cheap; do it first
  • Check: Tools scoped to the task, credentials read-only where possibleLeast privilege is the enforcement layer
  • Check: Human approval on irreversible actionsDeletion, payment, external send
  • Missing: Defined behaviour when a guardrail errorsFail closed on high-risk paths, and test it
  • Missing: Audit log of prompts, tool calls and decisionsWithout it you cannot investigate or improve
Run this before launch, not after the first incident. The two “missing” rows are the ones teams most often discover the hard way.

Traps the wrong answers are built from

Tempting but wrongDo this instead
Treating a system-prompt policy as the guardrailEnforce in code — validation, permissions, approvals — and keep the prompt as one layer.
A moderation call whose errors are treated as “no violation”Decide the failure mode explicitly and fail closed on high-risk paths.
A single binary block/allow thresholdGrade risk so the ambiguous middle reaches a human instead of being guessed at.
Giving the agent one broad credential for every capabilityScope credentials per tool, read-only by default, bound to the caller's identity.
Shipping guardrails without measuring themLabel real traffic and track precision and recall per category before and after launch.
Leaving permissions to individual configurationEnforce organisational standards centrally with managed settings.

You should now be able to

  • Write a content policy with decidable categories and graded risk levels.
  • Build a fast, structured moderation classifier and route its verdicts appropriately.
  • Layer deterministic and model-based guardrails, and say what each layer cannot catch.
  • Define fail-closed behaviour for a guardrail that errors, and test it.
  • Apply least privilege and session-bound identity to an agent's tools and credentials.
  • Run a pre-deployment guardrail review covering policy, screening, permissions, approval and audit.

Practice questions

Original questions written for this lesson, in the exam’s style. Answer first, then open the reasoning — every option is explained, including why the wrong ones are tempting.

  1. Question 1

    A social app moderates user posts with a fast model. Under load the moderation service times out for about two per cent of posts. The handler catches the exception, logs a warning and publishes the post.

    What is the most serious problem?

    1. AThe moderation model is too small for the traffic and should be upgraded.
    2. BThe guardrail fails open, so it disappears exactly when the system is stressed.
    3. CThe warning log does not include the post id, making investigation harder.
    4. DPosts should be moderated after publication so latency never blocks a user.
    Show answer and reasoning
    1. AIncorrect. Capacity may need attention, but a larger model would still time out under sufficient load.
    2. BCorrect. Treating an error as “no violation” means moderation silently stops applying during the periods most likely to be abused.
    3. CIncorrect. A real gap in observability, but far less serious than the bypass itself.
    4. DIncorrect. That converts a fail-open bug into a deliberate policy of publishing unmoderated content.
  2. Question 2

    An agent that files expense claims has a tool able to approve any claim under £5,000, using a service account. The team's review asks how to reduce risk without slowing the common case, which is small claims with a valid receipt.

    Which two changes follow secure-by-design principles? (Select 2.)

    1. AScope the approval tool so it can only act on claims belonging to the authenticated user's team.
    2. BRequire a human approval above a much lower value threshold.
    3. CAdd a system-prompt instruction to approve only legitimate claims.
    4. DLog approvals so anomalies can be found in a monthly review.
    5. ESwitch to a more capable model so judgements about claims improve.
    6. FRotate the service account credential more frequently.
    Show answer and reasoning
    1. ACorrect. Least privilege bounded by session identity limits what any successful manipulation can reach.
    2. BCorrect. It leaves the common small-claim path fast while putting a person in front of the consequential actions.
    3. CIncorrect. It advises the model without constraining the tool, so it adds no enforcement.
    4. DIncorrect. Auditing is necessary but detects after the fact; it is not itself a preventive control.
    5. EIncorrect. Better judgement does not change what the credential is permitted to do.
    6. FIncorrect. Good key hygiene, but it does not narrow what that credential can approve.
  3. Question 3

    A team builds a customer-facing assistant for a platform whose community rules permit frank discussion of topics that many services would filter. They write a detailed content policy allowing this, and find the model still declines some of it.

    What is the correct understanding?

    1. AThe system prompt needs to state the policy more forcefully so the model complies.
    2. BThe model's own usage policy applies as well; the effective policy is the narrower of the two.
    3. CThe application's policy always takes precedence once supplied in the system prompt.
    4. DMoving the policy into a tool result makes it authoritative for the model.
    Show answer and reasoning
    1. AIncorrect. The model's safety behaviour is not overridden by a stronger instruction, and pressing harder is not a design.
    2. BCorrect. The documentation warns that built-in safety behaviour can override an application's explicit policy, so the deployment must be planned around it.
    3. CIncorrect. The opposite is documented: application policy cannot widen what the model will do.
    4. DIncorrect. Tool results carry less authority, not more; the placement does not change safety behaviour.

Sources

Drafted with AI assistance and checked against the sources above; expert review is in progress. Spotted an error? Tell us and it gets fixed, dated and listed on how this is written.