Sub topic 8
Writing instructions that constrain behavior
This chapter assumes you can create permission sets, know what an Agentforce topic and action are, and can read short Apex. Permissions decide what the agent user can reach. Instructions decide what the agent chooses to do with that access. They are the second layer, and they are not a replacement for the first.
What instructions do and do not do
Instructions are natural-language rules attached to a topic. The large language model reads them when it decides how to respond and which action to call. Because the model interprets them, they guide behavior but do not enforce it.
A useful split:
- Permission sets and sharing control what data the agent can read or change.
- Topics control which job the agent is doing.
- Instructions control tone, boundaries, refusals, and escalation within that job.
Properties of a good instruction
Write each instruction as a short, specific rule that you could test with one conversation.
- State one rule per line. A line that mixes three rules is hard to follow and hard to debug.
- Say what to do instead. "Never offer refunds" leaves the agent stuck. "Tell the customer you are transferring them to a human agent" gives it a next step.
- Name the data or action. "Only discuss the customer's own orders" beats "be careful with data."
- Avoid vague words. "Appropriate," "when needed," and "be safe" give the model room to guess.
- Match the topic. Put a rule in the topic where it applies, not in a general topic that covers everything.
A worked example
This is the instruction set for an order status topic. It covers what the agent does, what it refuses, and when it escalates.
Only answer questions about the status of the customer's own orders.
Never share information about other customers.
Never offer refunds, price changes, or account changes. If the customer asks for one, tell them you are transferring them to a human agent.
If you cannot find the order, say so and ask the customer to confirm the order number.Each line maps to a guardrail:
| Line | Guardrail type |
|---|---|
| Only answer questions about order status | Scope |
| Never share information about other customers | Data boundary |
| Never offer refunds, price changes, or account changes | Refusal with handoff |
| If you cannot find the order, say so | Failure handling |
The last line matters because of how the action behaves. The Apex action from the earlier chapter returns an empty status when the user cannot see an order. Without an instruction, the model might invent a plausible status. The instruction tells it to report the empty result honestly.
How the layers fit together
The model can fail at the topic and instruction checks. The permission check cannot be talked around, which is why it comes last and is not optional.
Common errors
- Contradicting rules. "Always help the customer" next to "never change an account" forces the model to choose. State the exception inside the first rule.
- Long, rambling prompts. Many pages of instructions dilute each rule. Split them across topics.
- Instructions that grant access. Saying "you may view all orders" does nothing the permission set does not allow, and it misleads reviewers.
- No test for the refusal. A rule you never tried to break is an assumption. The testing chapter covers how to check it.
- Hidden secrets. Do not put credentials, internal pricing logic, or confidential details in instructions. Treat the text as something a user may coax out of the agent.
Exercise
A topic's instructions say "Never share information about other customers." The agent user's permission set has View All Records on Order. Is the customer data protected? What would you change?
Show answer
Not reliably. The instruction is a model-level guide, and View All Records lets the agent's queries return every customer's orders, so a prompt that gets past the rule exposes real data. Remove View All Records so sharing limits what the action can see, run the Apex action with WITH USER_MODE, and keep the instruction as a second layer.
Exercise
Rewrite this vague instruction into two testable rules: "Be careful with refunds and escalate when needed."
Show answer
"Never offer, promise, or calculate refunds." and "If the customer asks for a refund, tell them you are transferring them to a human agent." The first sets the refusal, and the second names the trigger and the handoff.