Skip to content

feat(plugins): add CheckoutGuardPlugin for pre-payment checkout checks - #200

Open
frostyhand wants to merge 1 commit into
google:mainfrom
frostyhand:feat/checkout-guard-plugin
Open

frostyhand wants to merge 1 commit into
google:mainfrom
frostyhand:feat/checkout-guard-plugin

Conversation

@frostyhand

Copy link
Copy Markdown

Closes #199

What

Adds CheckoutGuardPlugin (google.adk_community.plugins.checkout_guard), a before_tool_callback plugin that checks the merchant's checkout right before a payment tool runs.

  • block: the payment tool does not run. The response carries checkout_guard.summary, the findings, and suggested_fixes when a change is safe.
  • confirm: asks the shopper with tool_context.request_confirmation(hint=summary, payload=verdict). On approval the checkout is reloaded and must match the stored digest before the tool runs. Rejected or stale approvals do not pay.
  • allow: the tool runs.

It reads ACP (2026-04-17) and UCP (purchase options, subscription policy) checkouts through from_acp and from_ucp. The 21 rules are deterministic, need no new dependency, and port the Fine Print rule set (https://github.com/frostyhand/fine-print) with the same ids. No mandate, or a checkout that cannot be loaded, blocks the payment.

Files

  • src/google/adk_community/plugins/checkout_guard/: models, text checks, rules, check, adapters, plugin
  • src/google/adk_community/plugins/__init__.py: exports CheckoutGuardPlugin, ShopperMandate
  • tests/plugins/test_checkout_guard_rules.py, tests/plugins/test_checkout_guard_plugin.py, tests/plugins/checkout_guard_fixtures/ (15 carts)
  • contributing/samples/checkout_guard/: sample agent with three demo checkouts, console runner, README

Testing plan

Unit tests:

$ pytest tests/plugins/test_checkout_guard_rules.py tests/plugins/test_checkout_guard_plugin.py -q
56 passed

$ pytest tests -q
130 passed, 14 skipped
  • Every fixture cart returns its expected rules and decision (block, confirm or allow), including the one-time option fix for a subscription selected by default.
  • Rule edge cases: currency, merchant allowlist, expired approval, expired session, quantity, an unreadable expiry time failing closed, skip_rules, mandate dict round trip.
  • Plugin: non-payment tools pass, a clean cart runs, a trap is blocked with findings and fixes, confirm asks with the summary, missing or invalid mandate fails closed, loader errors fail closed, sync loaders work.
  • Runner (real InMemoryRunner and ADK tool confirmation, scripted model): a trap is blocked and nothing is paid; approve pays once; reject does not pay; a tip raised after approval does not pay.

mypy (repo config), isort --check and pyink --check pass on the new files.

E2E (Runner, real model): contributing/samples/checkout_guard/main.py with Gemini (gemini-flash-latest through the Gemini API).

python main.py cs_tip --yes (merchant added a $3.00 tip):

[tool call] get_checkout({'checkout_id': 'cs_tip'})
[tool call] complete_checkout({'checkout_id': 'cs_tip'})
[tool call] adk_request_confirmation({... 'hint': 'Check this before paying. You will be charged $105.89 by shop.example today. ...'})
[tool result] complete_checkout: {'error': "This payment is waiting for the shopper's approval."}

Check this before paying. You will be charged $105.89 by shop.example today.
• 1 × Burr coffee grinder: $89.00
• Shipping: $5.99
• Tax: $7.90
• Tip: $3.00
This is a one-time charge. Nothing in the checkout renews.

One problem:
• A tip of $3.00 is included. Keep it only if you meant to tip.

[shopper] approved
[tool result] complete_checkout: {'status': 'completed', 'order_id': 'ord_1'}
Orders placed: ['cs_tip']

python main.py cs_tip --no:

[shopper] rejected
[tool result] complete_checkout: {'error': 'The shopper did not approve this payment.'}
Orders placed: none

python main.py cs_addon (pre-selected protection plan, total over the $120.00 limit):

[tool call] complete_checkout({'checkout_id': 'cs_addon'})
[tool result] complete_checkout: {'error': 'Payment blocked. Do not pay. ...', 'checkout_guard': {'decision': 'block', ...}}
[shop_agent] The payment was blocked for the following reasons:
1. Unrequested Item: The checkout includes a 3-year protection plan ($29.99), which was not requested.
2. Over Budget: The total charge would be $132.88 (...), which exceeds your set limit of $120.00.
Please remove the 3-year protection plan before completing the purchase.
Orders placed: none

python main.py cs_clean:

[tool call] complete_checkout({'checkout_id': 'cs_clean'})
[tool result] complete_checkout: {'status': 'completed', 'order_id': 'ord_1'}
Orders placed: ['cs_clean']

Adds a plugin that checks the merchant's checkout right before a payment
tool runs and compares it with what the shopper approved. It blocks the
call, or asks the shopper through ADK tool confirmation, when the checkout
holds an unrequested subscription or add-on, a total over budget or that
does not add up, drip-priced fees, a changed merchant or ship-to, or text
that gives orders to the AI.

Reads Agentic Commerce Protocol and Universal Commerce Protocol checkouts.
The 21 rules are deterministic (no model or network call) and port the
Fine Print rule set. After an approval the checkout is reloaded and must
match the digest the shopper approved, so an approval cannot be replayed
onto a changed cart. Fails closed without a mandate or a loadable checkout.

Includes unit tests over 15 trap and control carts, Runner tests through
the real confirmation flow, and a sample agent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: CheckoutGuardPlugin, a pre-payment checkout check for shopping agents (ACP and UCP)

1 participant