Sub topic 14
Design practices: distinct topics, safe actions, and guardrails
This chapter assumes you know what topics, instructions, and actions are, and that you have tested an agent in Agentforce Builder. Here you will apply three design practices that make an agent predictable: keep topics distinct, keep actions safe, and put guardrails in the right place.
Keep topics distinct
The agent picks a topic by comparing the customer's request with each topic's name and classification description. If two descriptions overlap, the agent may pick either one, and the result changes from run to run.
Common causes of overlap:
- Two topics that both say "handle questions about orders".
- A broad catch-all topic next to specific ones.
- Classification descriptions that list what a topic does but never say what it does not do.
Fix overlap by giving each topic one job and naming its neighbors. The Order Status topic from earlier chapters does this:
Topic name: Order Status
Classification description:
Handle customer questions about where an existing order is and what its current status is. Do not use for returns, refunds, or new orders.The last sentence sends returns and refunds elsewhere. Write the matching sentence in the Returns topic too, so the boundary is stated from both sides.
A good check is to write five sample requests per topic and confirm in Builder that each lands in the intended topic. Add a few that sit on the boundary, such as "My order never arrived, I want my money back."
Keep actions safe
An action runs real logic against real data, so design it as if the agent will sometimes call it with unexpected input.
- Give each action one narrow purpose. A "Get Order Status" action is easier to reason about than a general "Manage Orders" action.
- Prefer read-only actions unless the topic needs to change data. The Order Status topic states that it cannot change or cancel orders, so it has no action that does.
- Enforce permissions in the action, not only in the instructions. The invocable Apex from the previous chapter uses
WITH USER_MODE, so the query respects the running user's object and field permissions. Instructions can be ignored by the model. Platform permissions cannot. - Handle empty results. The same Apex returns
Not foundwhen no order matches, so the agent has a defined value to react to. - Return only what the agent needs. The response exposes
Status, not the whole order record.
Put guardrails in the right layer
Different rules belong in different places. Choose the layer by how bad it is if the rule is broken.
| Rule | Where to enforce it | Why |
|---|---|---|
| Which requests a topic handles | Classification description and scope | Controls routing |
| How to talk and what steps to follow | Topic instructions | Guides reasoning, but is not guaranteed |
| Who can see or change which data | Apex user mode, sharing, permissions | Enforced by the platform |
| Actions that must not happen without a check | Flow or Apex logic with validation | Deterministic code |
Treat instructions as guidance and code as enforcement. An instruction like "Never share details about orders that belong to other customers" is useful, but it should be backed by sharing rules and user-mode queries so the data is never returned in the first place.
A review checklist
Before releasing an agent, check each topic and action against these questions:
- Can you state the topic's job in one sentence?
- Does every classification description say what the topic does not handle?
- Does each action do one thing, with labeled and described inputs and outputs?
- Do actions run with the user's permissions and handle empty results?
- Is every instruction that matters for security also enforced outside the prompt?
Exercise
A customer asks, "I got the wrong item, can I send it back and check where my replacement is?" Your agent has Order Status and Returns topics, and it sometimes picks the wrong one. Name two design changes that make routing more reliable, and one change that keeps the data safe whichever topic runs.
Show answer
Routing: add "Do not use for returns, refunds, or new orders" to Order Status and the matching exclusion to Returns, so each description names its neighbor. Also test boundary requests like this one in Builder and decide which topic owns them, or add a topic or an escalation path for mixed requests. Data safety: make the Apex or Flow behind each action enforce permissions, for example with WITH USER_MODE, so a wrong topic choice cannot expose data the user is not allowed to see.