firewallTool() wraps a tool function with a local policy check. The policy runs before the tool call. If the policy blocks, the original tool function is not executed.
When to use this
Use firewalls for tool calls that can have side effects, cost impact, or user impact. Examples:- Sending an email or Slack message
- Writing to a database
- Issuing a refund
- Calling an external API
- Running a destructive or high-cost action
How it works
You provide abeforeCall callback. The SDK calls it before the tool runs. The callback returns a policy decision such as ALLOW, WARN, BLOCK, or REQUIRE_APPROVAL.
The decision is recorded as part of the session. If the decision blocks the call, the SDK throws LynxPolicyError.
Example
Policy decisions
Failure modes
If policy evaluation itself throws,failureMode decides what happens.
What you can see in Lynx
Lynx can show:- The policy decision for a tool call
- Whether a tool was allowed, warned, blocked, or required approval
- The policy ID and policy version
- The blocked tool call in the session timeline
- Related errors and root cause candidates
Server availability
Firewall decisions are local. If the Lynx API is unavailable, the SDK still evaluates your policy callback. The policy decision event is queued and retried later.Notes
UseFAIL_CLOSED for high-risk actions where running the tool without a valid policy decision would be unsafe. Use FAIL_OPEN for low-risk actions where availability is more important than strict blocking.