Sub topic 10
Safeguards beyond confirmation
This chapter assumes you know how to turn on Require user confirmation for an action and how to reinforce it in topic instructions. It also assumes you can read a Flow or an Apex invocable method.
Confirmation protects against one failure: the agent misunderstood the request, or the user did not realize what would happen. It does not protect against an action that is too powerful, a value that should never be accepted, or a user who should not be changing the record at all. A user can also approve a bad change by clicking through. This chapter covers the controls that cover those gaps.
Confirmation is one layer
Think of an action as passing through several checks. Confirmation sits at the conversation level. The others sit in the data and code layers, where the agent's wording cannot override them.
Instructions and confirmation are guidance for the language model. Validation and permissions are enforced by the platform or by your code, so they hold even if the model behaves unexpectedly.
Least-privilege actions
Build each action to do one narrow job. An action named "Update Case Status" is safer than "Update Any Case Field", because the agent can only reach what the action exposes.
- Expose only the inputs the task needs. Do not pass a field name or an object name as an input.
- Prefer one action per operation. Keep delete actions separate from update actions, so you can leave delete actions out of a topic entirely.
- Give read-only actions and data-changing actions different names and descriptions, so the agent and the reviewer can tell them apart.
- Add an action to a topic only when that topic needs it.
Validate inputs inside the action
The agent collects values from the conversation, and those values can be wrong. Check them in the Flow or Apex, not only in the instructions. In a Flow, use a Decision element before the Update Records element. In Apex, check values before the DML statement.
Respect the running user's permissions
Find out which user the action runs as. A service agent usually runs as a designated agent user, and an employee-facing agent runs as the person chatting. Give that user only the permission sets the agent's actions require.
Apex needs extra care. with sharing applies sharing rules, but it does not enforce object permissions or field-level security. Run the DML in user mode to enforce them. For a Flow, check whether it runs in user context or system context. System context bypasses the running user's access, so use it only on purpose.
The version below tightens the Apex action from earlier in the tutorial. It accepts only an approved list of statuses and runs the update in user mode.
public with sharing class UpdateCaseStatusAction {
private static final Set<String> ALLOWED_STATUSES =
new Set<String>{ 'Working', 'Escalated', 'Closed' };
public class Request {
@InvocableVariable(required=true label='Case Id' description='The Id of the case to update')
public Id caseId;
@InvocableVariable(required=true label='New Status' description='Working, Escalated or Closed')
public String newStatus;
}
public class Result {
@InvocableVariable(label='Message' description='Outcome of the update')
public String message;
}
@InvocableMethod(
label='Update Case Status'
description='Changes the Status field of one case to Working, Escalated or Closed. This modifies data.'
)
public static List<Result> updateStatus(List<Request> requests) {
List<Result> results = new List<Result>();
List<Case> toUpdate = new List<Case>();
for (Request r : requests) {
Result res = new Result();
if (!ALLOWED_STATUSES.contains(r.newStatus)) {
res.message = 'Status ' + r.newStatus + ' is not allowed. No change made.';
} else {
toUpdate.add(new Case(Id = r.caseId, Status = r.newStatus));
res.message = 'Case ' + r.caseId + ' set to ' + r.newStatus;
}
results.add(res);
}
if (!toUpdate.isEmpty()) {
Database.update(toUpdate, AccessLevel.USER_MODE);
}
return results;
}
}If the user lacks edit access to Case or to the Status field, AccessLevel.USER_MODE makes the update fail instead of silently succeeding. The description now lists the allowed values, so the agent asks for one of them.
Other controls worth considering
| Control | What it prevents | Where it lives |
|---|---|---|
| Narrow action design | The agent reaching more data than needed | Action definition |
| Input validation | Invalid or out-of-policy values | Flow or Apex |
| User-mode access | Changes the running user may not make | Apex, Flow settings |
| Permission sets for the agent user | Over-broad access across all actions | Setup |
| Validation rules and approval processes | Bad data and unreviewed changes | Object configuration |
| Audit and review of conversations | Problems nobody noticed | Testing and monitoring |
Existing platform features also apply. A validation rule on Case blocks a bad update no matter who or what sends it.
Choosing what to combine
Match the controls to the risk.
- Read-only action: no confirmation needed. Keep permissions narrow.
- Low-risk, easily reversed update: confirmation plus validation is usually enough.
- Irreversible or high-impact change such as a delete, a bulk update, or a financial field: use confirmation, strict validation, user-mode access, and consider an approval process so a person other than the requester signs off.
A common mistake is to treat the confirmation setting as the only safeguard. If the action would be unsafe when a user says "yes" by accident, confirmation did not make it safe.
Exercise
An action lets the agent update any field on any Case by taking the field name and the new value as inputs. You turn on Require user confirmation. Name two other changes that would make this action safer.
Show answer
Replace it with narrow actions that each update one named field, such as Status, so field names are not inputs. Validate the new value inside the Flow or Apex against an allowed list. Running the update in user mode, or checking the running user's permission sets, would also be correct.
Exercise
Why does with sharing on an Apex class not guarantee that the running user can edit a field the action updates, and what do you add?
Show answer
with sharing enforces record-level sharing rules only. It does not check object permissions or field-level security. Run the DML in user mode, for example Database.update(records, AccessLevel.USER_MODE), to enforce them.