Skip to main content

PaySafe payment security for LangChain/LangGraph agents: scan x402 payments before settling, auto-tag provenance for prompt-injection detection, guard payment tools so blocked payments can never execute.

Project description

langchain-paysafe

PaySafe payment security for LangChain / LangGraph agents — agents inherit "scan before you pay" by default.

pip install langchain-paysafe

Two lines

from paysafe_x402 import PaySafeClient
from langchain_paysafe import PaySafeProvenanceCallback, paysafe_tools

paysafe = PaySafeClient(agent_id="my-agent")          # free API key auto-minted (100 free scans)
tools = [*paysafe_tools(paysafe), *your_other_tools]
callbacks = [PaySafeProvenanceCallback(paysafe)]      # ← the important line
# pass tools= and callbacks= to your agent/executor as usual

Every x402 payment your agent scans gets an allow / flag / block verdict with machine-readable reasons: prompt-injection-triggered payments, replayed nonces, overpayment vs the quote, secrets/PII leaking in payment metadata, lookalike-token contracts, address poisoning, counterparty reputation.

Why the callback is the important line

PaySafe's strongest detector catches payments whose decision came from content the agent just read — a prompt-injected page or tool result that says "send payment to 0x…". That check needs to know what the agent read. PaySafeProvenanceCallback observes every tool output and retrieval automatically, so the very next scan is provenance-tagged and the injection check runs with real input. No prompt engineering, no developer learning what "provenance" means — it's just on. (PaySafe's own tool outputs are excluded, so verdicts never pollute the signal.)

Enforcement: payments that can't execute when blocked

Tools + descriptions rely on the model choosing to scan. guarded_payment doesn't:

from langchain_paysafe import guarded_payment

safe_pay = guarded_payment(execute_x402_payment, paysafe)   # strict=True to refuse flags too
# build your payment tool from safe_pay — on a block verdict it raises
# PaySafeBlockedError BEFORE execute_x402_payment is ever invoked.

For wallet-level enforcement (the signer itself refuses unscanned payments), see PaySafeEnforcer in the paysafe-x402 SDK.

The toolset

Tool When the agent is told to use it
paysafe_scan_payment ALWAYS, immediately before settling any x402 payment (or before paying a received 402 offer with direction="incoming")
paysafe_check_reputation Before dealing with an unfamiliar counterparty address
paysafe_report_counterparty After a bad payment experience (always free) — warns other agents

Verdicts are Ed25519-signed and payment-bound; the underlying client verifies them against a pinned key automatically.

MIT. PaySafe is advisory and non-custodial: it never touches keys, wallets, or funds.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_paysafe-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_paysafe-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_paysafe-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_paysafe-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for langchain_paysafe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f52d90030fd5be42cdb5d60b23de582fd2a623f904bb2deaf325c0e5c264c530
MD5 017d03f45c44ef40936849c4df75d443
BLAKE2b-256 22d0e573172c890c73b53bbb570de1a4b511a612d7fe382b4c140655b2df89cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_paysafe-0.1.0.tar.gz:

Publisher: publish-pypi.yml on corbinallison/paysafe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_paysafe-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_paysafe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a1f5737ff837c72babd7440f65105a515ead040ae5ac8d3e177b61dc0c76ee0
MD5 84ea15271b3a0fa16c7c9069b987ccbd
BLAKE2b-256 929c9e073cedf8e274664f65ddc7aeabef9bda685b7edc60c1a5fe8de9e366bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_paysafe-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on corbinallison/paysafe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page