From 2ea73f4b02e6a3ca6c09df0252df7a1fc8e1be80 Mon Sep 17 00:00:00 2001 From: teodorofodocrispin-cmyk Date: Sat, 23 May 2026 23:43:49 -0500 Subject: [PATCH 1/5] feat(samples): add TrustBoost PII sanitization sample for AP2 + x402 autonomous payments --- .../pii-sanitization/README.md | 29 +++++++ .../pii-sanitization/agent.py | 80 +++++++++++++++++++ .../pii-sanitization/requirements.txt | 2 + 3 files changed, 111 insertions(+) create mode 100644 code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/README.md create mode 100644 code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/agent.py create mode 100644 code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/requirements.txt diff --git a/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/README.md b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/README.md new file mode 100644 index 00000000..c7413c34 --- /dev/null +++ b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/README.md @@ -0,0 +1,29 @@ +# AP2 Sample: PII Sanitization Before Autonomous Payment + +This sample demonstrates how an autonomous AI agent sanitizes PII from +text using **TrustBoost** before completing an **AP2 + x402** payment. + +## Scenario + +A shopping agent receives user-generated text containing PII. Before +sending to an LLM or completing an x402 payment, the agent calls +TrustBoost to redact PII and receive immutable proof on Solana. + +## Key Features + +- Autonomous PII sanitization via TrustBoost x402 protocol +- Proof of Sanitization anchored on Solana mainnet +- 8 languages: EN, ES-LATAM, PT-BR, DE, JA, FR, IT, KO +- EU AI Act compliant (Articles 12, 13, 26) + +## Quick Start + +pip install -r requirements.txt +python agent.py + +## Resources + +- TrustBoost: https://github.com/teodorofodocrispin-cmyk/TrustBoost-PII-Sanitizer +- Agent Card: https://api.trustboost.dev/.well-known/agent-card.json +- Health: https://api.trustboost.dev/health +- AP2 docs: https://ap2-protocol.org diff --git a/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/agent.py b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/agent.py new file mode 100644 index 00000000..bc902580 --- /dev/null +++ b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/agent.py @@ -0,0 +1,80 @@ +import os +import requests +from dotenv import load_dotenv + +load_dotenv() + +TRUSTBOOST_URL = "https://api.trustboost.dev" +TX_HASH = os.getenv("TRUSTBOOST_TX_HASH", "TRIAL") +WALLET = os.getenv("TRUSTBOOST_WALLET", "ap2-sample-agent") + + +def discover_trustboost(): + r = requests.get(f"{TRUSTBOOST_URL}/.well-known/agent-card.json", timeout=10) + r.raise_for_status() + card = r.json() + print(f"[TrustBoost] {card['name']} v{card['version']}") + print(f"[TrustBoost] Languages: {card['languages']}") + print(f"[TrustBoost] Compliance: {card['compliance']}") + return card + + +def sanitize_pii(text, context="general"): + print(f"\n[Sanitizing] {len(text)} chars, context={context}") + + # x402 flow: call without payment -> HTTP 402 -> pay -> retry + probe = requests.post(f"{TRUSTBOOST_URL}/sanitize", json={"text": text}, timeout=10) + if probe.status_code == 402: + x402 = probe.json().get("x402", {}) + accepts = x402.get("accepts", [{}])[0] + print(f"[x402] HTTP 402 - {accepts.get('amount')} {accepts.get('currency')} on {accepts.get('network')}") + print(f"[x402] Paying autonomously with tx_hash={TX_HASH}") + + r = requests.post( + f"{TRUSTBOOST_URL}/sanitize", + json={"text": text, "tx_hash": TX_HASH, "wallet_address": WALLET, "context": context}, + timeout=30 + ) + r.raise_for_status() + data = r.json().get("data", {}) + + print(f"[Result] {data.get('sanitized_content', '')[:80]}...") + print(f"[Score] {data.get('safety_score')} | Risk: {data.get('risk_category')}") + + proof = data.get("proof_of_sanitization") + if proof: + print(f"[Proof] {proof.get('verify_url')}") + + return data + + +def main(): + print("=" * 60) + print("AP2 Sample: PII Sanitization Before Autonomous Payment") + print("=" * 60) + + discover_trustboost() + + tests = [ + {"lang": "English (Financial)", "text": "Wire to john@acme.com, SSN 123-45-6789", "ctx": "financial"}, + {"lang": "Spanish LATAM (Legal)", "text": "RFC: LOPJ850101ABC, CURP: LOPJ850101HDFRZN09", "ctx": "legal"}, + {"lang": "Portuguese BR", "text": "CPF: 123.456.789-09, email: paciente@hospital.com.br", "ctx": "medical"}, + {"lang": "Japanese", "text": "田中太郎、マイナンバー:123456789012", "ctx": "general"}, + ] + + mode = "TRIAL (50 free)" if TX_HASH == "TRIAL" else "PAID (x402 Solana)" + print(f"\n[Mode] {mode}\n" + "=" * 60) + + for t in tests: + print(f"\n[{t['lang']}] {t['text']}") + try: + sanitize_pii(t["text"], t["ctx"]) + except Exception as e: + print(f"[Error] {e}") + + print("\nPII sanitized. Safe to proceed with AP2 payment.") + print(f"Verify: GET {TRUSTBOOST_URL}/verify/{{anchor_tx}}") + + +if __name__ == "__main__": + main() diff --git a/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/requirements.txt b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/requirements.txt new file mode 100644 index 00000000..2b1be2aa --- /dev/null +++ b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/requirements.txt @@ -0,0 +1,2 @@ +requests>=2.31.0 +python-dotenv>=1.0.0 From b5c50995361e746b81352f17b90e84979d0f9752 Mon Sep 17 00:00:00 2001 From: teodorofodocrispin-cmyk Date: Sat, 23 May 2026 23:52:05 -0500 Subject: [PATCH 2/5] =?UTF-8?q?fix(samples):=20address=20Gemini=20review?= =?UTF-8?q?=20=E2=80=94=20safer=20dict=20access,=20specific=20exception,?= =?UTF-8?q?=20efficient=20x402=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pii-sanitization/agent.py | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/agent.py b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/agent.py index bc902580..f92eb312 100644 --- a/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/agent.py +++ b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/agent.py @@ -13,9 +13,9 @@ def discover_trustboost(): r = requests.get(f"{TRUSTBOOST_URL}/.well-known/agent-card.json", timeout=10) r.raise_for_status() card = r.json() - print(f"[TrustBoost] {card['name']} v{card['version']}") - print(f"[TrustBoost] Languages: {card['languages']}") - print(f"[TrustBoost] Compliance: {card['compliance']}") + print(f"[TrustBoost] {card.get('name', 'Unknown')} v{card.get('version', '?')}") + print(f"[TrustBoost] Languages: {card.get('languages', [])}") + print(f"[TrustBoost] Compliance: {card.get('compliance', [])}") return card @@ -23,18 +23,17 @@ def sanitize_pii(text, context="general"): print(f"\n[Sanitizing] {len(text)} chars, context={context}") # x402 flow: call without payment -> HTTP 402 -> pay -> retry - probe = requests.post(f"{TRUSTBOOST_URL}/sanitize", json={"text": text}, timeout=10) - if probe.status_code == 402: - x402 = probe.json().get("x402", {}) - accepts = x402.get("accepts", [{}])[0] - print(f"[x402] HTTP 402 - {accepts.get('amount')} {accepts.get('currency')} on {accepts.get('network')}") + payload = {"text": text, "context": context} + r = requests.post(f"{TRUSTBOOST_URL}/sanitize", json=payload, timeout=10) + if r.status_code == 402: + x402 = r.json().get("x402", {}) + accepts_list = x402.get("accepts", []) + if accepts_list: + acc = accepts_list[0] + print(f"[x402] HTTP 402 - {acc.get('amount')} {acc.get('currency')} on {acc.get('network')}") print(f"[x402] Paying autonomously with tx_hash={TX_HASH}") - - r = requests.post( - f"{TRUSTBOOST_URL}/sanitize", - json={"text": text, "tx_hash": TX_HASH, "wallet_address": WALLET, "context": context}, - timeout=30 - ) + payload.update({"tx_hash": TX_HASH, "wallet_address": WALLET}) + r = requests.post(f"{TRUSTBOOST_URL}/sanitize", json=payload, timeout=30) r.raise_for_status() data = r.json().get("data", {}) @@ -69,7 +68,7 @@ def main(): print(f"\n[{t['lang']}] {t['text']}") try: sanitize_pii(t["text"], t["ctx"]) - except Exception as e: + except requests.exceptions.RequestException as e: print(f"[Error] {e}") print("\nPII sanitized. Safe to proceed with AP2 payment.") From 11b67fc38f922faf243f78dd517a5eec308f9b52 Mon Sep 17 00:00:00 2001 From: teodorofodocrispin-cmyk Date: Mon, 25 May 2026 23:52:16 -0500 Subject: [PATCH 3/5] fix(spellcheck): add TrustBoost and PII identifier terms to custom dictionary --- .cspell/custom-words.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.cspell/custom-words.txt b/.cspell/custom-words.txt index ce73c361..6c98f1de 100644 --- a/.cspell/custom-words.txt +++ b/.cspell/custom-words.txt @@ -185,3 +185,19 @@ XVCJ Yapily Zalopay Zalora + +CNPJ +CURP +LOPJ +NIR +Personalausweis +RRN +SIRET +Sanitizer +TRUSTBOOST +TrustBoost +sanitization +sanitize +sanitized +sanitizer +trustboost \ No newline at end of file From 86dcae641cc4472c57e3873abe042953ecbca10e Mon Sep 17 00:00:00 2001 From: teodorofodocrispin-cmyk Date: Mon, 25 May 2026 23:55:17 -0500 Subject: [PATCH 4/5] fix(spellcheck): add HDFRZN and mainnet to custom dictionary --- .cspell/custom-words.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.cspell/custom-words.txt b/.cspell/custom-words.txt index 6c98f1de..9c14d554 100644 --- a/.cspell/custom-words.txt +++ b/.cspell/custom-words.txt @@ -200,4 +200,6 @@ sanitization sanitize sanitized sanitizer -trustboost \ No newline at end of file +trustboost +HDFRZN +mainnet \ No newline at end of file From 646db96e75dafbe1401b84bc47ea4054061f9289 Mon Sep 17 00:00:00 2001 From: teodorofodocrispin-cmyk Date: Tue, 26 May 2026 00:05:51 -0500 Subject: [PATCH 5/5] fix(docs): add fenced code block and markdown links to README --- .../a2a/human-not-present/pii-sanitization/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/README.md b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/README.md index c7413c34..913842e7 100644 --- a/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/README.md +++ b/code/samples/python/scenarios/a2a/human-not-present/pii-sanitization/README.md @@ -18,12 +18,14 @@ TrustBoost to redact PII and receive immutable proof on Solana. ## Quick Start +```bash pip install -r requirements.txt python agent.py +``` ## Resources -- TrustBoost: https://github.com/teodorofodocrispin-cmyk/TrustBoost-PII-Sanitizer -- Agent Card: https://api.trustboost.dev/.well-known/agent-card.json -- Health: https://api.trustboost.dev/health -- AP2 docs: https://ap2-protocol.org +- [TrustBoost](https://github.com/teodorofodocrispin-cmyk/TrustBoost-PII-Sanitizer) +- [Agent Card](https://api.trustboost.dev/.well-known/agent-card.json) +- [Health](https://api.trustboost.dev/health) +- [AP2 docs](https://ap2-protocol.org)