---
editLink: false
lastUpdated: false
---

[@salesforce/b2c-tooling-sdk](../../modules.md) / [safety](../index.md) / withSafetyConfirmation

# Function: withSafetyConfirmation()

> **withSafetyConfirmation**\<`T`\>(`guard`, `operation`, `confirmHandler`): `Promise`\<`T`\>

Defined in: [packages/b2c-tooling-sdk/src/safety/with-confirmation.ts:68](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/safety/with-confirmation.ts#L68)

Execute an operation with safety confirmation support.

If the operation throws [SafetyConfirmationRequired](../classes/SafetyConfirmationRequired.md), the
`confirmHandler` is called. If the user confirms, the operation
is retried with a temporary exemption. If the user cancels (or
the handler returns false), a [SafetyBlockedError](../../errors/classes/SafetyBlockedError.md) is thrown.

Non-confirmation errors are re-thrown as-is.

## Type Parameters

### T

`T`

## Parameters

### guard

[`SafetyGuard`](../classes/SafetyGuard.md)

The SafetyGuard instance

### operation

() => `Promise`\<`T`\>

The operation to execute

### confirmHandler

[`ConfirmHandler`](../type-aliases/ConfirmHandler.md)

Context-specific confirmation handler

## Returns

`Promise`\<`T`\>

The operation's return value

## Example

```typescript
// CLI usage
const result = await withSafetyConfirmation(
  guard,
  () => instance.ocapi.POST('/jobs/import/executions', ...),
  async (eval) => {
    if (!process.stdin.isTTY) return false;
    return confirm(`Safety: ${eval.reason}. Proceed?`);
  },
);

// VS Code usage
const result = await withSafetyConfirmation(
  guard,
  () => runJobImport(),
  async (eval) => {
    const choice = await vscode.window.showWarningMessage(eval.reason, { modal: true }, 'Proceed');
    return choice === 'Proceed';
  },
);
```
