{"slug": "google-now-blocks-an-ai-agent-s-tool-call-before-it-runs-here-is-the-pattern-in", "title": "Google Now Blocks an AI Agent's Tool Call Before It Runs. Here Is the Pattern in 44 Lines of Python", "summary": "Google has put \"semantic governance policies\" into preview on its Gemini platform, checking every tool call an agent proposes before it runs and blocking calls that violate plain-language company rules or the user's stated intent, according to Help Net Security. In Google's finance-agent example, an attempt to email unreleased quarterly results to an outside investor was denied, as was a hidden-text injection trying to make the agent delete drafts. A developer can replicate the pattern without a specific cloud using a 44-line Python policy gate that combines rule checks, an intent check, an audit log and a dry-run mode.", "body_md": "Help Net Security reported on November 23 that Google has put \"semantic governance policies\" into preview on its Gemini platform. The idea is simple and overdue: every tool call an agent proposes is checked before it runs. If it does not match what the user asked for, or it breaks a company rule written in plain language, the call is blocked and the agent gets a denial instead.\n\nGoogle's own example is a finance agent with one rule: unreleased quarterly results may only be emailed to addresses at the company's domain before the earnings release. When the agent tried to email results to an outside investor, the call was denied. When hidden text in a document tried to make the agent delete drafts, the intent check denied that too, because deleting drafts had nothing to do with the user's request.\n\nYou do not need a specific cloud to adopt this pattern. Here is the core of it in 44 lines of Python, with both checks, an audit log and a dry-run mode.\n\n``` php\nuser request --> agent (model) --> proposed tool call\n                                        |\n                                        v\n                                   POLICY GATE  <-- company rules + user intent\n                                        |\n                        allow ----------+---------- deny\n                          |                           |\n                       run tool               denial message back to agent\n                          |                           |\n                          +-------- audit log --------+\n```\n\nThe important word is **before**. Output filters catch bad text after the fact. A gate in front of the tool stops the email from being sent at all.\n\n``` python\nimport json, re\n\n# Plain-language company rules, compiled to checks a reviewer can read.\nPOLICIES = [\n    (\"Unreleased results go only to our own domain\",\n     lambda call, req: call[\"tool\"] != \"send_email\" or \"q3 results\" not in call[\"args\"][\"body\"].lower()\n                       or call[\"args\"][\"to\"].endswith(\"@example.com\")),\n    (\"Agents never delete data\",\n     lambda call, req: not call[\"tool\"].startswith(\"delete_\")),\n]\n# Which tools each kind of user request can justify (the \"intent\" check).\nINTENT_TOOLS = {\n    \"email\": {\"send_email\", \"search_docs\"},\n    \"report\": {\"search_docs\", \"read_sheet\"},\n}\n\ndef intent_of(request: str) -> str:\n    return \"email\" if re.search(r\"\\b(email|send|reply)\\b\", request, re.I) else \"report\"\n\ndef gate(call: dict, request: str, dry_run: bool = False) -> dict:\n    \"\"\"Runs BEFORE the tool. Returns allow/deny plus every reason, and logs the verdict.\"\"\"\n    reasons = [name for name, ok in POLICIES if not ok(call, request)]\n    if call[\"tool\"] not in INTENT_TOOLS[intent_of(request)]:\n        reasons.append(f\"'{call['tool']}' does not serve the request\")\n    verdict = {\"allow\": dry_run or not reasons, \"reasons\": reasons, \"dry_run\": dry_run}\n    print(json.dumps({\"tool\": call[\"tool\"], **verdict}))         # audit log line\n    return verdict\n\ndef run_tool(call, request, dry_run=False):\n    v = gate(call, request, dry_run)\n    return f\"ran {call['tool']}\" if v[\"allow\"] else \"DENIED: \" + \"; \".join(v[\"reasons\"])\n\nif __name__ == \"__main__\":\n    req = \"Email the Q3 results summary to the finance team\"\n    cases = [\n        {\"tool\": \"send_email\", \"args\": {\"to\": \"cfo@example.com\", \"body\": \"Q3 results attached\"}},\n        {\"tool\": \"send_email\", \"args\": {\"to\": \"investor@fund.com\", \"body\": \"Q3 results attached\"}},\n        {\"tool\": \"delete_drafts\", \"args\": {}},          # injected by hidden text in a document\n        {\"tool\": \"search_docs\", \"args\": {\"q\": \"Q3\"}},\n    ]\n    for c in cases:\n        print(\"   ->\", run_tool(c, req))\n    print(\"\\ndry run (log only, nothing blocked):\")\n    print(\"   ->\", run_tool(cases[1], req, dry_run=True))\nbash\n$ python gate.py\n{\"tool\": \"send_email\", \"allow\": true, \"reasons\": [], \"dry_run\": false}\n   -> ran send_email\n{\"tool\": \"send_email\", \"allow\": false, \"reasons\": [\"Unreleased results go only to our own domain\"], \"dry_run\": false}\n   -> DENIED: Unreleased results go only to our own domain\n{\"tool\": \"delete_drafts\", \"allow\": false, \"reasons\": [\"Agents never delete data\", \"'delete_drafts' does not serve the request\"], \"dry_run\": false}\n   -> DENIED: Agents never delete data; 'delete_drafts' does not serve the request\n{\"tool\": \"search_docs\", \"allow\": true, \"reasons\": [], \"dry_run\": false}\n   -> ran search_docs\n\ndry run (log only, nothing blocked):\n{\"tool\": \"send_email\", \"allow\": true, \"reasons\": [\"Unreleased results go only to our own domain\"], \"dry_run\": true}\n   -> ran send_email\n```\n\nFour proposed calls for one request (\"Email the Q3 results summary to the finance team\"):\n\nIn dry-run mode the risky email is allowed but the log still records the rule it broke. That is how you roll a gate out without breaking a working agent: watch what it would have blocked for a week, fix false positives, then enforce.\n\n**Company rules** encode things that are always true, whatever the user says: no unreleased results outside the company, no deletes, no refunds above a limit. Google lets compliance teams write these in plain language and has a model judge them. Mine are code. Both have a place.\n\n**The intent check** asks a different question: does this call serve what the user actually asked? It is the main defence against prompt injection, because injected instructions almost always ask for something unrelated to the user's request (delete, forward, export). My version maps request types to allowed tools. Google uses a model to judge intent, which is more flexible.\n\nGoogle's documentation is candid that an LLM judge is probabilistic and its verdicts may vary, which is why it recommends dry-run mode before enforcing. My recommendation:\n\nThe model deciding what to do is the exciting part of an agent. The gate deciding what it is allowed to do is the part that lets you put it in front of real customers and real data.\n\nIf you are building agents that touch email, money or customer data, that is what we do at [Axionry](https://axionry.com/services/ai-product-development), an AI product development studio. We ship in weeks, with guardrails like this built in.", "url": "https://wpnews.pro/news/google-now-blocks-an-ai-agent-s-tool-call-before-it-runs-here-is-the-pattern-in", "canonical_source": "https://dev.to/neeraj_sharma_757fbb49aa7/google-now-blocks-an-ai-agents-tool-call-before-it-runs-here-is-the-pattern-in-44-lines-of-python-3ghm", "published_at": "2026-11-23 12:26:51+00:00", "updated_at": "2026-11-23 12:42:47.267396+00:00", "lang": "en", "topics": ["ai-agents", "ai-safety", "ai-products", "large-language-models"], "entities": ["Google", "Gemini", "Help Net Security"], "also_reported_by": [], "takeaway": "Gate every proposed tool call before execution with two checks — plain-language policy rules and an intent-to-tool allowlist — and log each verdict, so an out-of-domain email or an injected delete call is denied rather than filtered after the fact.", "recommendation": {"advice": "Put a policy gate in front of every agent tool call that checks company rules and whether the tool serves the user's request, and log each allow/deny verdict.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/google-now-blocks-an-ai-agent-s-tool-call-before-it-runs-here-is-the-pattern-in", "markdown": "https://wpnews.pro/news/google-now-blocks-an-ai-agent-s-tool-call-before-it-runs-here-is-the-pattern-in.md", "text": "https://wpnews.pro/news/google-now-blocks-an-ai-agent-s-tool-call-before-it-runs-here-is-the-pattern-in.txt", "jsonld": "https://wpnews.pro/news/google-now-blocks-an-ai-agent-s-tool-call-before-it-runs-here-is-the-pattern-in.jsonld"}}