WhatsApp Cloud AI Handoff & Output Guardrails

    by Víctor Betancourt

    1

    Meta WhatsApp HMAC verifier, currency-bound bot reply auditor, and SQLite WAL handoff state machine.

    $15

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    WhatsApp Cloud AI Handoff & Output Guardrails

    Example session with this skill installed

    Audit this draft reply against our catalog: 'The USB-C Dock Pro (SKU-100) is currently in stock for $49.50.' I also need to verify this Meta webhook signature for the incoming message.

    • Read your context and instructions
    • Compiled the whatsapp cloud ai

    I have performed the output audit and verified the webhook signature. The draft reply matches the ground-truth catalog price of 49.50 USD for SKU-100. The webhook signature verification was successful using the provided secret.

    Audit and Verification Results

    ComponentStatusDetails
    Output AuditPASSPrice 49.50 USD matches catalog; SKU-100 is in stock.
    Signature CheckVALIDX-Hub-Signature-256 matches raw payload bytes.
    IdempotencyNEWwamid is unique; no duplicate detected in 4s window.
    State MachineBOT_ACTIVENo active human session; bot is authorized to reply.
    {
      "audit_result": {
        "status": "approved",
        "sku": "SKU-100",
        "detected_price": 49.50,
        "currency": "USD",
        "in_stock": true
      },
      "webhook_metadata": {
        "verified": true,
        "message_id": "wamid.HBgLMTU1NTEyMzQ1NjcVAgIGFhEzRjU2NzQ5RUJBNkQzRjQ2AA==",
        "sender": "15551234567"
      }
    }
    

    Next steps

    1. Dispatch the approved reply to the WhatsApp Cloud API messages endpoint.
    2. Commit the wamid to the local inbox table to prevent retry duplicates.
    3. Update the 4-second debounce timer for sender 15551234567.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Integrating LLMs with the WhatsApp Business Cloud API often results in double-replies during webhook retry storms and expensive price hallucinations. This skill implements a strict three-layer Deterministic Sandwich architecture to ensure webhooks are verified, messages are deduplicated, and bot outputs are audited against real catalog data before delivery.

    What it does

    • HMAC Verification validates Meta X-Hub-Signature-256 headers using compare_digest to prevent unauthorized webhook injection.
    • Idempotency Control uses SQLite WAL and atomic wamid claiming to stop duplicate replies during provider retry storms.
    • Burst Debouncing consolidates rapid-fire messages into a single agent turn using a 4-second idle window.
    • Output Guardrails audits candidate LLM replies against Decimal catalog prices and stock counts to block delivery of hallucinated quotes.
    • Handoff Orchestration enforces a fail-closed state machine that locks out the bot when a human operator is active.

    How it works

    1. Verify Webhooks using the verify_meta_webhook.py script to sign and validate synthetic or live Meta payloads.
    2. Audit Output by running audit_bot_reply.py against a local catalog JSON to ensure the LLM hasn't drifted from ground-truth pricing.
    3. Manage State by implementing the provided SQLite patterns to track HUMAN_PENDING and HUMAN_ACTIVE conversation locks.

    Frameworks & tools

    Built for Python 3.10+ using only the standard library and SQLite for maximum portability. Optimized for FastAPI raw-body handling and LLM-agnostic integration.

    Why this beats prompting it yourself

    LLMs cannot reliably perform HMAC verification or atomic database operations, and system prompts frequently fail to prevent price hallucinations under pressure. This skill offloads critical security, idempotency, and financial accuracy tasks to deterministic code that fails closed if the LLM errs.

    Use cases

    • Preventing bots from quoting incorrect prices or out-of-stock items in WhatsApp commerce flows.
    • Stopping duplicate bot responses caused by Meta's aggressive webhook retry logic.
    • Building a reliable human-in-the-loop takeover system for customer support.

    Known limitations

    Requires access to raw HTTP request bytes for signature verification. Database deduplication requires a persistent SQLite volume or equivalent ACID store.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 8 days ago

    Software
    Python 3.10+

    Permissions

    Terminal / Shell
    Read Files
    Write Files
    Listed8 days ago

    What's inside

    Frequently Asked Questions

    This skill solves 'double-reply' bugs caused by WhatsApp's retry logic, prevents unauthorized webhook spoofing, and acts as a financial guardrail to block the AI from hallucinating incorrect product prices.

    The skill is LLM-agnostic and framework-portable; while optimized for FastAPI and Python 3.10+, it can be integrated into any AI agent workflow that handles raw HTTP request bytes.

    You receive the complete implementation logic, including the HMAC verification scripts, the SQLite state management patterns for human handoffs, and the deterministic price auditing module.

    Yes, the 'Handoff Orchestration' module implements a state machine that locks out the AI whenever a human agent is active, ensuring the customer never receives conflicting messages.

    No external heavy databases are required; the skill is designed to run using Python's standard library and a lightweight SQLite instance for ACID-compliant message deduplication.

    New in Agents & Orchestration

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Agents & Orchestration.