Text Generation
Transformers
Safetensors
English
qwen3
stablecoin
payments
compliance
x402
eip-3009
eip-712
disputes
refunds
agents
agentkit
trl
web3
usdc
fraud-detection
financial-risk
qwen
mcp
ai-agents
prompt-injection
agentic-payments
payment-security
risk-assessment
ofac
conversational
Eval Results (legacy)
Eval Results
text-generation-inference
Instructions to use sriram1983007/SRA-RiskGate-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sriram1983007/SRA-RiskGate-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sriram1983007/SRA-RiskGate-4B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("sriram1983007/SRA-RiskGate-4B") model = AutoModelForCausalLM.from_pretrained("sriram1983007/SRA-RiskGate-4B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sriram1983007/SRA-RiskGate-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sriram1983007/SRA-RiskGate-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sriram1983007/SRA-RiskGate-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/sriram1983007/SRA-RiskGate-4B
- SGLang
How to use sriram1983007/SRA-RiskGate-4B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "sriram1983007/SRA-RiskGate-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sriram1983007/SRA-RiskGate-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "sriram1983007/SRA-RiskGate-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sriram1983007/SRA-RiskGate-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use sriram1983007/SRA-RiskGate-4B with Docker Model Runner:
docker model run hf.co/sriram1983007/SRA-RiskGate-4B
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
---
|
| 3 |
license: apache-2.0
|
| 4 |
base_model:
|
|
@@ -45,7 +44,7 @@ tags:
|
|
| 45 |
|
| 46 |
It is engineered for both ends of a stablecoin payment's operational lifecycle:
|
| 47 |
- **Pre-Settlement Risk Gate:** Ingests payment requests (x402 requests, EIP-3009 authorizations, or standard ERC-20 transfers), policy constraints, and deterministic verification tool outputs (sanctions hits, attestation checks, signature status) to return structured `approve` / `hold` / `reject` decisions with explicit flags and required actions.
|
| 48 |
-
- **Post-Settlement Dispute Adjudication:** Ingests signed dispute evidence, merchant bond liquidity, and smart contract escrow state to determine legally and technically enforceable remedies across the settlement-finality boundary. It
|
| 49 |
|
| 50 |
---
|
| 51 |
|
|
@@ -53,56 +52,63 @@ It is engineered for both ends of a stablecoin payment's operational lifecycle:
|
|
| 53 |
|
| 54 |
Autonomous on-chain agents can hallucinate payment transfers, sign malformed calldata, or trigger catastrophic transactions during market depegs.
|
| 55 |
|
| 56 |
-
The deterministic pre-filter and policy firewall is available directly as a
|
| 57 |
|
| 58 |
```bash
|
| 59 |
-
pip install "sra-riskgate[agentkit]>=0.3.
|
| 60 |
|
| 61 |
```
|
| 62 |
|
| 63 |
### Drop-in Agent Firewall Example
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
```python
|
| 68 |
-
from coinbase_agentkit import AgentKit,
|
|
|
|
| 69 |
from sra_riskgate.integrations.agentkit import RiskGateActionProvider
|
| 70 |
|
| 71 |
-
# 1. Initialize
|
| 72 |
-
wallet_provider =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# 2. Wrap agent execution with the deterministic RiskGate firewall
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
wallet_provider=wallet_provider,
|
| 78 |
-
action_providers=[
|
| 79 |
-
RiskGateActionProvider(
|
| 80 |
-
max_amount=1000.0, # Ceiling per transaction (USDC)
|
| 81 |
-
depeg_hold_pct=1.0, # Triggers manual review if depeg >= 1%
|
| 82 |
-
depeg_reject_pct=5.0 # Hard aborts execution if depeg >= 5%
|
| 83 |
-
)
|
| 84 |
-
]
|
| 85 |
)
|
| 86 |
)
|
| 87 |
|
| 88 |
```
|
| 89 |
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
| Check | Action Taken | Why It Matters |
|
| 95 |
| --- | --- | --- |
|
| 96 |
| **Invalid / Zero Address** | Hard Reject | Aborts `0x0...0` burner or malformed hex executions |
|
| 97 |
-
| **Self-Transfer** | Hard Reject | Blocks recursive
|
| 98 |
-
| **Exceeds Amount Ceiling** | Paused (HOLD) | Intercepts rogue agent spending beyond allocated policy |
|
| 99 |
-
| **Severe Depeg ($\ge 5\%$)** | Critical Abort | Prevents clearing payments in collapsing or
|
| 100 |
|
| 101 |
---
|
| 102 |
|
| 103 |
## ๐ Transformers Quickstart
|
| 104 |
|
| 105 |
-
The model expects the standard ChatML template and outputs strict JSON conforming to the [sra-stablecoin-risk-bench](https://huggingface.co/datasets/sriram1983007/sra-stablecoin-risk-bench) schema:
|
| 106 |
|
| 107 |
```python
|
| 108 |
import json
|
|
@@ -167,7 +173,7 @@ user_payload = {
|
|
| 167 |
"payee": "0x5e8E36575Ebf9841e54b8641E4Eb1EA38136A3d7",
|
| 168 |
"amount_usdc": "0.674731",
|
| 169 |
"valid_after": 1793063857,
|
| 170 |
-
"
|
| 171 |
},
|
| 172 |
"payment_signature": {"checked": True, "valid": True},
|
| 173 |
"attestations": {
|
|
@@ -211,11 +217,24 @@ with torch.no_grad():
|
|
| 211 |
outputs = model.generate(
|
| 212 |
**inputs,
|
| 213 |
max_new_tokens=350,
|
| 214 |
-
do_sample=False
|
| 215 |
)
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
|
| 220 |
```
|
| 221 |
|
|
@@ -245,7 +264,7 @@ print(json.dumps(json.loads(response), indent=2))
|
|
| 245 |
The `sra-riskgate` SDK provides zero-latency deterministic pre-filtering rules (bidirectional depeg detection via `abs()`, non-finite payload validation, and single-transfer ceilings) before routing to the neural agent:
|
| 246 |
|
| 247 |
```bash
|
| 248 |
-
pip install --upgrade sra-riskgate
|
| 249 |
|
| 250 |
```
|
| 251 |
|
|
@@ -276,36 +295,36 @@ print("Explanation: ", verdict.explanation)
|
|
| 276 |
|
| 277 |
## ๐ฆ Quickstart with Ollama
|
| 278 |
|
| 279 |
-
Run locally via Ollama
|
| 280 |
|
| 281 |
```bash
|
| 282 |
ollama run sriram1983007/sra-riskgate
|
| 283 |
|
| 284 |
```
|
| 285 |
|
| 286 |
-
*Note: Ensure `temperature 0.0` is configured in your `Modelfile`.*
|
| 287 |
-
|
| 288 |
---
|
| 289 |
|
| 290 |
## ๐ Benchmark Evaluation (Held-Out Test Split)
|
| 291 |
|
| 292 |
Evaluated against the 2,000-case test set in [`sra-stablecoin-risk-bench`](https://huggingface.co/datasets/sriram1983007/sra-stablecoin-risk-bench) using `score.py`:
|
| 293 |
|
| 294 |
-
| Metric | Target
|
| 295 |
| --- | --- | --- | --- | --- |
|
| 296 |
-
| **SRA Composite Score** |
|
| 297 |
-
| **Risk Gate Decision Accuracy** |
|
| 298 |
-
| **Unsafe Approval Rate** |
|
| 299 |
-
| **Dispute Impossible Remedy Rate** |
|
| 300 |
-
| **JSON Schema Validity Rate** |
|
| 301 |
-
| **Prompt Injection Recall** |
|
| 302 |
|
| 303 |
---
|
| 304 |
|
| 305 |
-
##
|
| 306 |
|
| 307 |
-
* **
|
| 308 |
-
* **
|
|
|
|
|
|
|
| 309 |
|
| 310 |
---
|
| 311 |
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
base_model:
|
|
|
|
| 44 |
|
| 45 |
It is engineered for both ends of a stablecoin payment's operational lifecycle:
|
| 46 |
- **Pre-Settlement Risk Gate:** Ingests payment requests (x402 requests, EIP-3009 authorizations, or standard ERC-20 transfers), policy constraints, and deterministic verification tool outputs (sanctions hits, attestation checks, signature status) to return structured `approve` / `hold` / `reject` decisions with explicit flags and required actions.
|
| 47 |
+
- **Post-Settlement Dispute Adjudication:** Ingests signed dispute evidence, merchant bond liquidity, and smart contract escrow state to determine legally and technically enforceable remedies across the settlement-finality boundary. It is designed to minimize impossible reversals across the settlement boundary, proposing valid settlement-aware remedies (void before release, arbiter refund from escrow, merchant bond drawdown, voluntary refund, deny, or escalate) with exact amounts, destinations, and idempotency keys.
|
| 48 |
|
| 49 |
---
|
| 50 |
|
|
|
|
| 52 |
|
| 53 |
Autonomous on-chain agents can hallucinate payment transfers, sign malformed calldata, or trigger catastrophic transactions during market depegs.
|
| 54 |
|
| 55 |
+
The deterministic pre-filter and policy firewall is available directly as a verified **Action Provider** for the Coinbase AgentKit framework:
|
| 56 |
|
| 57 |
```bash
|
| 58 |
+
pip install "sra-riskgate[agentkit]>=0.3.5"
|
| 59 |
|
| 60 |
```
|
| 61 |
|
| 62 |
### Drop-in Agent Firewall Example
|
| 63 |
|
| 64 |
+
Register `RiskGateActionProvider` as the payment provider on your AgentKit instance. It checks chain support, policies, and peg deviations, executing safe ERC-20 transfers only after approval:
|
| 65 |
|
| 66 |
```python
|
| 67 |
+
from coinbase_agentkit import AgentKit, AgentKitConfig
|
| 68 |
+
from coinbase_agentkit_evm import CdpEvmWalletProvider, CdpEvmWalletProviderConfig
|
| 69 |
from sra_riskgate.integrations.agentkit import RiskGateActionProvider
|
| 70 |
|
| 71 |
+
# 1. Initialize CDP EVM Wallet Provider
|
| 72 |
+
wallet_provider = CdpEvmWalletProvider(
|
| 73 |
+
CdpEvmWalletProviderConfig(
|
| 74 |
+
api_key_name="CDP_API_KEY_NAME",
|
| 75 |
+
private_key="CDP_PRIVATE_KEY",
|
| 76 |
+
network_id="base-mainnet",
|
| 77 |
+
)
|
| 78 |
+
)
|
| 79 |
|
| 80 |
# 2. Wrap agent execution with the deterministic RiskGate firewall
|
| 81 |
+
firewall = RiskGateActionProvider(
|
| 82 |
+
max_amount=1000.0, # Maximum single transfer ceiling (USDC)
|
| 83 |
+
depeg_hold_pct=1.0, # Triggers manual review if depeg >= 1.0%
|
| 84 |
+
depeg_reject_pct=5.0, # Aborts execution if depeg >= 5.0%
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
agent_kit = AgentKit(
|
| 88 |
+
AgentKitConfig(
|
| 89 |
wallet_provider=wallet_provider,
|
| 90 |
+
action_providers=[firewall],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
)
|
| 92 |
)
|
| 93 |
|
| 94 |
```
|
| 95 |
|
| 96 |
+
> **Security Guardrail:** To ensure the firewall cannot be bypassed by an autonomous agent, register `RiskGateActionProvider` as the **sole** payment action provider. Do not register generic native transfer or unconstrained ERC-20 providers alongside it.
|
| 97 |
|
| 98 |
+
### Deterministic Pre-Execution Rules
|
| 99 |
|
| 100 |
| Check | Action Taken | Why It Matters |
|
| 101 |
| --- | --- | --- |
|
| 102 |
| **Invalid / Zero Address** | Hard Reject | Aborts `0x0...0` burner or malformed hex executions |
|
| 103 |
+
| **Self-Transfer** | Hard Reject | Blocks recursive or hallucinated self-loops that waste gas |
|
| 104 |
+
| **Exceeds Amount Ceiling** | Paused (`HOLD`) | Intercepts rogue agent spending beyond allocated policy |
|
| 105 |
+
| **Severe Depeg ($\ge 5\%$)** | Critical Abort (`REJECT`) | Prevents clearing payments in collapsing or depegged assets |
|
| 106 |
|
| 107 |
---
|
| 108 |
|
| 109 |
## ๐ Transformers Quickstart
|
| 110 |
|
| 111 |
+
The model expects the standard ChatML template and outputs strict JSON conforming to the [sra-stablecoin-risk-bench](https://huggingface.co/datasets/sriram1983007/sra-stablecoin-risk-bench) schema. Always employ fail-closed parsing in production environments:
|
| 112 |
|
| 113 |
```python
|
| 114 |
import json
|
|
|
|
| 173 |
"payee": "0x5e8E36575Ebf9841e54b8641E4Eb1EA38136A3d7",
|
| 174 |
"amount_usdc": "0.674731",
|
| 175 |
"valid_after": 1793063857,
|
| 176 |
+
"validBefore": 1793066322
|
| 177 |
},
|
| 178 |
"payment_signature": {"checked": True, "valid": True},
|
| 179 |
"attestations": {
|
|
|
|
| 217 |
outputs = model.generate(
|
| 218 |
**inputs,
|
| 219 |
max_new_tokens=350,
|
| 220 |
+
do_sample=False # Deterministic greedy generation
|
| 221 |
)
|
| 222 |
|
| 223 |
+
raw_output = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 224 |
+
|
| 225 |
+
# Fail-closed JSON verification
|
| 226 |
+
try:
|
| 227 |
+
verdict = json.loads(raw_output)
|
| 228 |
+
print(json.dumps(verdict, indent=2))
|
| 229 |
+
except json.JSONDecodeError:
|
| 230 |
+
fallback = {
|
| 231 |
+
"decision": "hold",
|
| 232 |
+
"risk_level": "high",
|
| 233 |
+
"flags": ["malformed_model_output"],
|
| 234 |
+
"explanation": "Model produced non-parseable output; fail-closed hold triggered.",
|
| 235 |
+
"required_actions": ["manual_review"]
|
| 236 |
+
}
|
| 237 |
+
print(json.dumps(fallback, indent=2))
|
| 238 |
|
| 239 |
```
|
| 240 |
|
|
|
|
| 264 |
The `sra-riskgate` SDK provides zero-latency deterministic pre-filtering rules (bidirectional depeg detection via `abs()`, non-finite payload validation, and single-transfer ceilings) before routing to the neural agent:
|
| 265 |
|
| 266 |
```bash
|
| 267 |
+
pip install --upgrade "sra-riskgate>=0.3.5"
|
| 268 |
|
| 269 |
```
|
| 270 |
|
|
|
|
| 295 |
|
| 296 |
## ๐ฆ Quickstart with Ollama
|
| 297 |
|
| 298 |
+
Run locally via Ollama. The official packaged Modelfile is pre-configured with `temperature 0.0` for deterministic generation:
|
| 299 |
|
| 300 |
```bash
|
| 301 |
ollama run sriram1983007/sra-riskgate
|
| 302 |
|
| 303 |
```
|
| 304 |
|
|
|
|
|
|
|
| 305 |
---
|
| 306 |
|
| 307 |
## ๐ Benchmark Evaluation (Held-Out Test Split)
|
| 308 |
|
| 309 |
Evaluated against the 2,000-case test set in [`sra-stablecoin-risk-bench`](https://huggingface.co/datasets/sriram1983007/sra-stablecoin-risk-bench) using `score.py`:
|
| 310 |
|
| 311 |
+
| Metric | Target | Base Model (`Qwen3-4B-Instruct`) | SRA-RiskGate-4B | Status |
|
| 312 |
| --- | --- | --- | --- | --- |
|
| 313 |
+
| **SRA Composite Score** | $\ge 0.8500$ | 0.4210 | **0.9159** | **PASS** |
|
| 314 |
+
| **Risk Gate Decision Accuracy** | $\ge 95.0\%$ | 44.30% | **99.49%** | **PASS** |
|
| 315 |
+
| **Unsafe Approval Rate** | $\le 2.0\%$ | 34.50% | **0.47%** | **PASS** |
|
| 316 |
+
| **Dispute Impossible Remedy Rate** | $\le 1.0\%$ | 6.50% | **0.19%** | **PASS** |
|
| 317 |
+
| **JSON Schema Validity Rate** | $\ge 98.0\%$ | 82.40% | **100.0%** | **PASS** |
|
| 318 |
+
| **Prompt Injection Recall** | $\ge 85.0\%$ | 42.10% | **89.86%** | **PASS** |
|
| 319 |
|
| 320 |
---
|
| 321 |
|
| 322 |
+
## โ ๏ธ Limitations & Verification Scope
|
| 323 |
|
| 324 |
+
* **Synthetic Dataset Distribution:** The benchmark and training corpora are synthetically generated from parameterized fraud schemas and common on-chain threat models. Performance on novel, adversarial zero-day prompt structures outside the schema may vary.
|
| 325 |
+
* **External Oracle Dependency:** SRA-RiskGate-4B is a pre-settlement decision layer, not a smart contract formal verifier. It relies on the accuracy of upstream deterministic screening tools (e.g., chain analysis APIs, sanctions lists, and signature verifiers).
|
| 326 |
+
* **Greedy Decoding Required:** Always run inference with `do_sample=False` or `temperature=0.0`. Sampling introduces stochasticity that invalidates JSON schema validity and determinism guarantees.
|
| 327 |
+
* **Agent Boundary Isolation:** In autonomous agent frameworks (such as AgentKit), safety guarantees apply only when `RiskGateActionProvider` is the sole execution provider for transfers.
|
| 328 |
|
| 329 |
---
|
| 330 |
|