Reference · Tools for AI clients

confirm

signature
confirm(str) -> bool

What it does

In a tool (fn mcp), asks the person at the AI client a yes-or-no question and gives their answer: true when they tick the box, false when they send it back unticked. The call stops at the question: the client is sent a form (MCP's input_required), asks the person, and calls the tool again with the answer, and the function then runs again from the top, so this time confirm gives the answer and the code goes on. A tool therefore asks before it changes anything. Outside a tool's call (the program's own code, or a page calling a server fn mcp) it gives true at once: the page asks in its own way. See Tools for AI clients.

Examples

in a program
db.open("notes.db")/// Deletes every note, after asking the person.fn mcp clear_notes() -> int ! str with db {    let n = db.one("select count(*) as n from notes").n    if !confirm(`Delete all ${n} notes?`) { return err("nothing was deleted: the user said no") }    db.exec("delete from notes")    n}

The first call of clear_notes reads the count and stops at confirm: the client is sent a form with one box, titled Delete all 2 notes? and unticked. Ticked and sent back, the tool runs again, confirm is true, and the client gets 2. Left unticked, the model gets the tool's own error, nothing was deleted: the user said no, and nothing is deleted.

Outside a tool's call there is no one to ask, so it is true:

print(confirm("Delete all notes?"))
output
true

Edge cases

Errors

An empty question stops the program (or the call), as nothing would be asked:

this one fails
print(confirm(""))
output
line 1: `confirm`'s question is empty: say what the user is asked

quillo check refuses a question that is not text: argument 1 of `confirm` must be str, got int.

Chaining

It reads as a condition, before the change it guards. Piped, the question is what comes in:

print("Send the newsletter now?" | confirm)
output
true
in a program
/// Puts the newsletter in the outbox for every subscriber.fn mcp send_newsletter(subject: str) -> int ! str with db {    let n = db.one("select count(*) as n from subscribers").n    if !confirm(`Send "${subject}" to ${n} people?`) { return err("not sent: the user said no") }    db.exec("insert into outbox (subscriber, subject) select id, ? from subscribers", subject)    n}

See also

ask, mcp_token, err, Tools for AI clients

Thread
1Useful? Like it, or add to its thread below.

Thread 0 posts

On confirm(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo