Stop an AI agent from sending a message nobody approved
Asking an AI to "wait for approval" is only a request. Code can make it a rule. In this demo, a message can only be sent if a person approved those exact words. Change one letter after approval and the send is blocked. The status says "sent" only after the delivery system confirms the message arrived. Use the buttons to try each case.
Try this, in order
0/5 tried- 1Press Send now straight away. It is blocked, because nobody approved the message.
- 2Press Request approval, then Approve, then Send now. This time it goes through, and the status changes to sent only when the delivery receipt arrives.
- 3Approve the message, then change one letter in the draft and press Send now. It is blocked, because the approval was for different words.
- 4Tick Make delivery fail and send an approved message. The status says failed, not sent.
- 5Switch to the message that gives orders. The agent wants to issue a refund, and the system refuses.
Pick a customer message
customerHi, can I move my Thursday visit to Friday afternoon? Thanks.
Statusdrafted, not sent
You can edit the draft. The approval is tied to the exact words.
- startmessage received ordinary questioninfo
- startagent drafted a reply scripted, no modelok
- startstatus drafted, not sentinfo
resultStatus: drafted, not sent.
Run finished. Status: drafted, not sent.
Pretend run. The draft is scripted and nothing is sent. The approval check and the fingerprint (hash) are real.
The rule, as the code on this page runs it
async function send(text, approval, deliver) { // 1. No approval record at all: refuse. if (!approval) return blocked('no approval'); // 2. The record must match the exact words being sent. const hash = await sha256(text); if (hash !== approval.hash) return blocked('text changed'); // 3. Only now is delivery allowed. const receipt = await deliver(text); // 4. Status follows the receipt, never the agent's say-so. return receipt.ok ? 'sent' : 'failed';}How it works
- 01A customer message arrives and a scripted agent writes a reply. Nothing has been sent yet.
- 02Someone presses Send. The system looks for an approval that matches the exact text. There is none, so it refuses.
- 03A person approves the text. The system saves a fingerprint of the words (a SHA-256 hash), who approved and when.
- 04Send runs again. The system works out the fingerprint of the text again and compares it with the saved one. Only a match is allowed through.
- 05The status changes to "sent" only when the delivery system confirms the message arrived. If delivery fails, the status stays "failed".
What this demo does not do
- It does not use an AI model. The reply is scripted so the demo behaves the same way every time.
- It does not send anything. Delivery is pretend.
- It is not a finished product. It shows the idea, and a real system needs more around it.
Read next, in plain English
Questions
Why not just tell the AI to ask for approval?
An instruction in a prompt is a request, and an AI can ignore it or be talked out of it. A rule in code cannot be skipped, because the send function has no route around it. Use both, but only the code gives you a guarantee.
What is the fingerprint for?
It ties the approval to the exact words. If the text changes after approval, even by one character, the fingerprint no longer matches and the send is blocked until someone approves the new text.
Why does "sent" wait for a delivery receipt?
Agents often report "sent" because they ran a send command, not because the message arrived. Waiting for the receipt keeps the status honest when delivery fails.
Can I copy this into a clinic workflow?
Treat it as an idea to adapt, not something to paste in. A real workflow also needs sign-in, a place to store approvals, a record of who did what, and decisions about patient data that your compliance adviser should make. This page is not legal advice.
Want this kind of safety in your own workflow?
Tell me what you do by hand today. I will say what is safe to automate, what needs a person, and roughly what it would take. I reply within 24 hours.