sentinel-scam-honeypo / tests /test_schema_hardening.py
avinash-rai's picture
Deployment Ready: Fixed scam detection low confidence, added production audit report, optimized throttles
1838600
import json
from app.core.llm_client import LLMClient
import asyncio
async def test_hardening():
client = LLMClient()
# Mocking a basic schema with an optional field
schema = {
"type": "object",
"properties": {
"name": {"type": "string", "description": "The target name"},
"wallet_address": {"type": "string", "description": "Optional ETH address"},
"confidence": {"type": "number", "minimum": 0, "maximum": 1}
},
"required": ["name"]
}
# We want to see if wallet_address and confidence become nullable and required
from app.core.llm_client import GroqClient
groq_client = GroqClient()
hardened = groq_client._harden_schema_for_strict_mode(schema)
print("\n--- ORIGINAL SCHEMA ---")
print(json.dumps(schema, indent=2))
print("\n--- HARDENED SCHEMA (STRICT MODE) ---")
print(json.dumps(hardened, indent=2))
# Verification assertions (in print form for audit)
props = hardened.get("properties", {})
is_wallet_nullable = "null" in props["wallet_address"]["type"]
is_confidence_nullable = "null" in props["confidence"]["type"]
is_name_required = "name" in hardened["required"]
is_wallet_required = "wallet_address" in hardened["required"]
is_additional_props_false = hardened.get("additionalProperties") is False
print(f"\nVerification Results:")
print(f" - additionalProperties: False? {is_additional_props_false}")
print(f" - Wallet Nullable? {is_wallet_nullable}")
print(f" - Confidence Nullable? {is_confidence_nullable}")
print(f" - Wallet Required? {is_wallet_required}")
print(f" - Name Required? {is_name_required}")
if all([is_additional_props_false, is_wallet_nullable, is_confidence_nullable, is_wallet_required, is_name_required]):
print("\n [PASSED] Schema hardening logic is Groq-Compliant.")
else:
print("\n [FAILED] Schema hardening logic violated constraints.")
if __name__ == "__main__":
asyncio.run(test_hardening())