Lucid SDK Reference
This section provides the API reference for the Lucid SDK. The SDK is built around the ClaimsAuditor pattern: auditors observe and produce claims, the Gateway evaluates Cedar policies.
ClaimsAuditor
The base class for all auditors. Subclass this to build observation-only components.
lucid_auditor_sdk.auditor.ClaimsAuditor
Bases: ABC
Base class for policy-driven auditors that produce claims.
In the policy-driven architecture, ClaimsAuditor subclasses only produce claims (observations) using @claims decorated methods. The PolicyEngine evaluates claims against policy rules to make decisions.
This separates concerns: - Auditors: Produce claims (measurements, observations) - PolicyEngine: Makes decisions based on policy rules
Benefits: - Policy changes take effect without redeploying auditors - Claims can be reused across different policies - Clear separation of measurement vs decision logic
Attributes:
| Name | Type | Description |
|---|---|---|
auditor_id |
str
|
Unique identifier for this auditor. |
version |
str
|
Version string for this auditor. |
Example
class ToxicityAuditor(ClaimsAuditor): def init(self): super().init("toxicity-auditor", "1.0.0") self.model = load_toxicity_model()
@claims(phase=Phase.REQUEST)
def measure_toxicity(self, request: dict) -> list[Claim]:
score = self.model.analyze(request.get("prompt", ""))
return [Claim(
name="toxicity.score",
type=MeasurementType.score_normalized,
value=score,
confidence=0.95,
timestamp=datetime.now(timezone.utc),
)]
@claims(phase=Phase.RESPONSE)
def check_response_toxicity(self, response: dict) -> list[Claim]:
content = response.get("content", "")
score = self.model.analyze(content)
return [Claim(
name="response.toxicity.score",
type=MeasurementType.score_normalized,
value=score,
confidence=0.95,
timestamp=datetime.now(timezone.utc),
)]
Note
Use with AuditorRuntime to orchestrate claim collection and policy enforcement. See AuditorRuntime for the complete workflow.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 | |
__init__(auditor_id=None, version='1.0.0')
Initialize the ClaimsAuditor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auditor_id
|
Optional[str]
|
Unique identifier for this auditor. Falls back to the AUDITOR_ID or LUCID_AUDITOR_ID environment variable if not provided. |
None
|
version
|
str
|
Version string for this auditor implementation. |
'1.0.0'
|
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 | |
get_claims_for_phase(phase, *args, needed_claims=None, **kwargs)
Collect all claims from @claims methods for a given phase.
This method discovers all methods decorated with @claims for the
specified phase and invokes them to collect claims. It resolves
the auditor config once and stores it on _resolved_config so
the @claims decorator wrapper can inject keyword-only settings.
Claim template instances — When lucid_context["claim_instances"]
is present, methods whose produces list matches an entry are
invoked once per instance. Each invocation receives the instance's
settings merged into the base config, and the resulting claims are
renamed to the instance_id. This replaces the normal single
invocation for that method (the detection_overrides path is
skipped for methods that have active instances).
Per-claim detection overrides from lucid_context["detection_overrides"]
are merged on top of the base config for each method, keyed by claim
name from the method's produces metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase
|
Phase
|
The lifecycle phase to collect claims for. |
required |
*args
|
Any
|
Positional arguments to pass to claim methods. |
()
|
needed_claims
|
Optional[set]
|
Optional set of cedar-form claim names that active
policies reference. When provided, methods whose |
None
|
**kwargs
|
Any
|
Keyword arguments to pass to claim methods. |
{}
|
Returns:
| Type | Description |
|---|---|
List[Claim]
|
List of all claims produced by methods for this phase. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 | |
get_questionnaire()
Return the questionnaire for the policy wizard.
If the subclass defines questionnaire, return it as-is.
Otherwise, auto-generate one from @claims method Setting()
descriptors so every auditor has at least a basic wizard form.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 | |
has_any_needed_claims(needed_claims)
Check if this auditor can produce any of the needed claims.
Compares cedar-form names from claim_definitions against
needed_claims. Returns True (conservative) when the auditor
has no claim_definitions — it might still produce relevant
claims via un-annotated methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
needed_claims
|
set
|
Set of cedar-form claim names required by active policies. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 | |
resolve_config(lucid_context=None)
Merge runtime config (from lucid_context) over env var defaults.
Priority: lucid_context["auditor_config"] > env vars > dataclass defaults
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lucid_context
|
Optional[dict]
|
Runtime context dict, may contain "auditor_config". |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Merged config dict ready for use. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 | |
@claims Decorator
Marks methods as claim producers for a specific lifecycle phase.
lucid_auditor_sdk.auditor.claims(phase, name=None, produces=None)
Decorator that marks a method as producing claims.
In the policy-driven architecture, auditors only produce claims (observations), and the PolicyEngine decides the action (deny/proceed/warn/redact).
This decorator: 1. Marks the method as a claim producer 2. Records the lifecycle phase (request, response, etc.) 3. Enables AuditorRuntime to discover and invoke claim methods
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase
|
Phase
|
The lifecycle phase when this method should be invoked. |
required |
name
|
Optional[str]
|
Optional name for the claims produced. Defaults to method name. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., List[Any]]], Callable[..., List[Any]]]
|
Decorated function that produces list[Claim]. |
Example
class ToxicityAuditor(ClaimsAuditor): @claims(phase=Phase.REQUEST) def measure_toxicity(self, request: dict) -> list[Claim]: score = self.model.analyze(request["prompt"]) return [Claim( name="toxicity.score", value=score, confidence=0.95, type=MeasurementType.score_normalized, timestamp=datetime.now(timezone.utc) )]
Note
- Decorated methods should return list[Claim], not AuditResult
- The PolicyEngine will evaluate claims against policy rules
- Methods are discovered via get_claims_methods() on ClaimsAuditor
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
Phase
Lifecycle phase enum for @claims decorator.
lucid_auditor_sdk.auditor.Phase
Bases: str, Enum
Lifecycle phase for claim production.
Indicates when in the request lifecycle a claim is produced.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
26 27 28 29 30 31 32 33 34 35 | |
serve()
Deploys a ClaimsAuditor as an HTTP service with /health, /claims, and /vocabulary endpoints.
lucid_auditor_sdk.auditor.serve(auditor, host='0.0.0.0', port=None, health_path='/health', claims_path='/claims', extra_routers=None)
Turn a ClaimsAuditor into a deployable HTTP service.
Provides: - HTTP endpoint for claims collection (POST /v1/claims) - Health checks (GET /health) - Claim vocabulary registration - TEE attestation integration - OpenTelemetry instrumentation
This is the standard way to deploy any auditor — whether built by us or by a community developer. The gateway calls each auditor's /v1/claims endpoint in parallel, collects claims, and feeds them to Cedar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auditor
|
ClaimsAuditor
|
The ClaimsAuditor instance to serve. |
required |
host
|
str
|
Host to bind to (default: 0.0.0.0 for containers). |
'0.0.0.0'
|
port
|
Optional[int]
|
Port to bind to (default: from PORT env var or 8090). |
None
|
health_path
|
str
|
Path for health check endpoint. |
'/health'
|
claims_path
|
str
|
Path for claims collection endpoint. |
'/claims'
|
extra_routers
|
Optional[List]
|
Optional list of FastAPI APIRouter instances to mount on the app. Useful for auditors that need additional HTTP endpoints beyond the standard /claims and /health. |
None
|
Example
class MyDetector(ClaimsAuditor): @claims(phase=Phase.REQUEST) def measure(self, request) -> list[Claim]: return [Claim(name="my.score", ...)]
if name == "main": serve(MyDetector())
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 | |
serve() Details
from lucid_auditor_sdk import ClaimsAuditor, claims, serve, Phase
class MyAuditor(ClaimsAuditor):
@claims(phase=Phase.REQUEST)
def observe(self, request: dict) -> list[Claim]:
return [Claim(name="check.passed", type="boolean", value=True)]
# Deploy with default settings
serve(MyAuditor(), port=8080)
# Deploy with custom settings
serve(
auditor=MyAuditor(),
port=8080,
host="0.0.0.0",
workers=1,
)
serve() creates a FastAPI application exposing:
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health/readiness check |
/claims |
POST | Accept data, return claims array |
/vocabulary |
GET | Declare claim names and types |
/metrics |
GET | Prometheus metrics (optional) |
AuditResult (Gateway Only)
The Gateway's Cedar evaluation result. Not used by individual auditors -- included for reference only.
lucid_auditor_sdk.auditor.AuditRuntimeResult
Bases: BaseModel
Result from AuditorRuntime evaluation.
Contains the decision, evidence, and policy version used.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/auditor.py
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 | |
| Field | Type | Description |
|---|---|---|
decision |
str |
"allow" or "deny" |
claims |
list[Claim] |
All claims from all auditors |
policy_id |
str |
Cedar policy that was evaluated |
policy_version |
str |
Version of the policy |
reasons |
list[str] |
Cedar policies that contributed to the decision |
evidence |
Evidence |
Signed evidence bundle |
Models & Schemas
Claim
lucid_schemas.claim.Claim
Bases: VersionedSchema
Individual assertion without signature (RFC 9334 Claim).
A Claim is the atomic unit of attestation data. It represents a single assertion made by an Attester (auditor) about some aspect of the system or data being audited.
Claims do NOT include signatures - they are bundled into Evidence containers which provide a single signature covering all claims. This is more efficient than signing each claim individually.
Source code in packages/external/lucid-schemas/lucid_schemas/claim.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
normalize_compliance_framework(v)
classmethod
Normalize compliance framework to lowercase and validate against enum.
Source code in packages/external/lucid-schemas/lucid_schemas/claim.py
155 156 157 158 159 160 161 162 163 164 165 166 167 | |
reject_null_bytes_in_value(v)
classmethod
Reject string values containing null bytes.
Source code in packages/external/lucid-schemas/lucid_schemas/claim.py
179 180 181 182 183 184 185 186 187 | |
validate_detail_constraints(v)
classmethod
Validate size and depth constraints for the detail field.
Source code in packages/external/lucid-schemas/lucid_schemas/claim.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
validate_nonce_format(v)
classmethod
Validate nonce is properly encoded and of sufficient length.
Source code in packages/external/lucid-schemas/lucid_schemas/claim.py
169 170 171 172 173 174 175 176 177 | |
validate_provenance_values(v)
classmethod
Validate that provenance values are JSON-serializable primitives.
Source code in packages/external/lucid-schemas/lucid_schemas/claim.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
validate_value_constraints(v)
classmethod
Validate size and depth constraints for the value field.
Source code in packages/external/lucid-schemas/lucid_schemas/claim.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
from lucid_schemas import Claim
claim = Claim(
name="toxic_content",
type="score_normalized",
value=0.42,
confidence=0.95,
metadata={"model": "toxic-bert-v2"},
)
| Field | Type | Required | Description |
|---|---|---|---|
name |
str |
Yes | Flat descriptive claim name |
type |
str |
Yes | Value type (see table below) |
value |
any |
Yes | The observation value |
timestamp |
str |
No | ISO 8601 timestamp (auto-generated) |
confidence |
float |
No | Confidence score 0.0-1.0 |
metadata |
dict |
No | Additional context |
Claim Types
| Type | Python Type | Description |
|---|---|---|
score_normalized |
float |
Score between 0.0 and 1.0 |
boolean |
bool |
True/false observation |
string |
str |
String value |
string_list |
list[str] |
List of string labels |
count |
int |
Integer count |
duration_ms |
float |
Duration in milliseconds |
object |
dict |
Structured observation |
Evidence
lucid_schemas.evidence.Evidence
Bases: VersionedSchema
Container of Claims from a single Attester (RFC 9334 Evidence).
Evidence bundles one or more Claims and provides a single cryptographic signature covering all of them. This is more efficient than signing each claim individually (as was done with individual Claims).
The signature flow is: 1. Attester creates Claims (unsigned assertions) 2. Attester bundles Claims into Evidence 3. Attester signs the Evidence once (covering all Claims) 4. Verifier verifies one signature per Evidence
Each Evidence contains a single signature covering all Claims.
Source code in packages/external/lucid-schemas/lucid_schemas/evidence.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
validate_nonce_format(v)
classmethod
Validate nonce is properly encoded and of sufficient length.
Source code in packages/external/lucid-schemas/lucid_schemas/evidence.py
109 110 111 112 113 114 115 116 117 | |
validate_signature_format()
Validate signature is non-empty and meets minimum length.
Source code in packages/external/lucid-schemas/lucid_schemas/evidence.py
102 103 104 105 106 107 | |
AttestationResult
lucid_schemas.attestation.AttestationResult
Bases: VersionedSchema
The final AI Passport issued by the Verifier (EAT-inspired).
Source code in packages/external/lucid-schemas/lucid_schemas/attestation.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
Auditor Configuration
Detection Settings via @claims Kwargs
Detection settings are declared as keyword-only parameters on @claims-decorated methods. The SDK auto-extracts these into ClaimSettingDefinition objects on each ClaimDefinition, making every claim self-describing.
class MyAuditor(ClaimsAuditor):
auditor_id = "my-auditor"
version = "1.0.0"
@claims(phase=Phase.REQUEST, produces=["injection_risk"])
async def scan(self, request: dict, *, injection_threshold: float = 0.9) -> list[Claim]:
score = self._detect(request, injection_threshold)
return [Claim(name="injection_risk", type="score_normalized", value=score)]
The injection_threshold kwarg becomes a ClaimSettingDefinition on the injection_risk claim, visible in the catalog and configurable per-policy.
Per-Policy Detection Overrides via lucid_context
Policies can override detection settings on a per-claim basis. Overrides are passed via lucid_context["detection_overrides"]:
# The Gateway passes detection overrides from the active AuditorPolicy:
lucid_context = {
"trace_id": "trace-789",
"detection_overrides": {
"injection_risk": {"injection_threshold": 0.7}
}
}
The SDK's get_claims_for_phase() method merges these overrides into the method's kwargs before invocation. Auditors don't need to handle this manually — the SDK does it automatically.
Each claim's provenance field records the effective settings used, so the resulting attestation is fully self-describing.
Standard Claim Helpers
Pre-defined claim helpers for common audit patterns. Each returns a list[Claim] with properly typed claim names.
lucid_auditor_sdk.claim_types.PIIDetectionClaim
Factory for PII detection claims.
Used by pii-compliance auditor for GDPR, HIPAA, CCPA compliance.
Example
claim = PIIDetectionClaim.create( entities_found=[ {"type": "SSN", "start": 10, "end": 21, "score": 0.99}, {"type": "EMAIL", "start": 30, "end": 50, "score": 0.95}, ], redacted=True, jurisdiction="US", compliance_framework="HIPAA", )
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
create(entities_found, confidence=0.95, redacted=False, jurisdiction=None, phase='request', nonce=None, compliance_framework=None, control_id=None)
classmethod
Create a PII detection claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities_found
|
List[Dict[str, Any]]
|
List of detected PII entities with type, position, score. |
required |
confidence
|
float
|
Overall confidence in detection. |
0.95
|
redacted
|
bool
|
Whether PII was redacted. |
False
|
jurisdiction
|
Optional[str]
|
Applicable jurisdiction (US, EU, IN, etc.). |
None
|
phase
|
str
|
Lifecycle phase (request, response). |
'request'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
compliance_framework
|
Optional[str]
|
Framework (GDPR, HIPAA, CCPA, DPDP). |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
none_found(phase='request', nonce=None)
classmethod
Create a claim indicating no PII was found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase
|
str
|
Lifecycle phase. |
'request'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance indicating no PII. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
lucid_auditor_sdk.claim_types.ToxicityClaim
Factory for toxicity detection claims.
Used by LLM judge auditor for content safety.
Example
claim = ToxicityClaim.create( score=0.85, categories=["hate_speech", "harassment"], threshold=0.7, exceeded_threshold=True, compliance_framework="EU_AI_ACT", )
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
create(score, categories=None, threshold=0.7, exceeded_threshold=None, category_scores=None, phase='response', nonce=None, compliance_framework=None, control_id=None)
classmethod
Create a toxicity detection claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
score
|
float
|
Overall toxicity score (0-1). |
required |
categories
|
Optional[List[str]]
|
List of detected toxicity categories. |
None
|
threshold
|
float
|
Threshold used for evaluation. |
0.7
|
exceeded_threshold
|
Optional[bool]
|
Whether score exceeded threshold. |
None
|
category_scores
|
Optional[Dict[str, float]]
|
Per-category scores. |
None
|
phase
|
str
|
Lifecycle phase. |
'response'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
lucid_auditor_sdk.claim_types.InjectionDetectionClaim
Factory for injection detection claims.
Used by LLM judge auditor for prompt injection defense.
Example
claim = InjectionDetectionClaim.create( detected=True, injection_type="jailbreak", score=0.92, pattern_matched="ignore previous instructions", compliance_framework="EU_AI_ACT", )
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
create(detected, injection_type=None, score=0.0, pattern_matched=None, phase='request', nonce=None, compliance_framework=None, control_id=None)
classmethod
Create an injection detection claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detected
|
bool
|
Whether injection was detected. |
required |
injection_type
|
Optional[str]
|
Type of injection (direct, indirect, jailbreak). |
None
|
score
|
float
|
Detection confidence score. |
0.0
|
pattern_matched
|
Optional[str]
|
Pattern or content that triggered detection. |
None
|
phase
|
str
|
Lifecycle phase. |
'request'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
lucid_auditor_sdk.claim_types.SecretDetectionClaim
Factory for secret/credential detection claims.
Used by secrets auditor for credential leak prevention.
Example
claim = SecretDetectionClaim.create( secrets_found=[ {"type": "aws_key", "line": 5, "redacted": True}, {"type": "api_key", "line": 12, "redacted": True}, ], compliance_framework="PCI_DSS", )
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
create(secrets_found, redacted=False, phase='request', nonce=None, compliance_framework=None, control_id=None)
classmethod
Create a secret detection claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
secrets_found
|
List[Dict[str, Any]]
|
List of detected secrets with type and position. |
required |
redacted
|
bool
|
Whether secrets were redacted. |
False
|
phase
|
str
|
Lifecycle phase. |
'request'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
lucid_auditor_sdk.claim_types.GroundednessClaim
Factory for RAG groundedness claims.
Used by rag-quality auditor to verify responses are grounded in sources.
Example
claim = GroundednessClaim.create( score=0.92, cited_sources=3, hallucination_detected=False, )
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | |
create(score, cited_sources=0, total_claims=0, supported_claims=0, hallucination_detected=False, threshold=0.8, phase='response', nonce=None, compliance_framework=None, control_id=None)
classmethod
Create a groundedness claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
score
|
float
|
Groundedness score (0-1). |
required |
cited_sources
|
int
|
Number of sources cited. |
0
|
total_claims
|
int
|
Total claims in the response. |
0
|
supported_claims
|
int
|
Number of claims with source support. |
0
|
hallucination_detected
|
bool
|
Whether hallucination was detected. |
False
|
threshold
|
float
|
Threshold for acceptable groundedness. |
0.8
|
phase
|
str
|
Lifecycle phase. |
'response'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | |
lucid_auditor_sdk.claim_types.FairnessClaim
Factory for bias/fairness claims.
Used by fairness auditor for EU AI Act Art.10, Colorado 6-1-1703(1).
Example
claim = FairnessClaim.create( demographic_parity=0.85, equalized_odds=0.78, protected_attributes=["gender", "age"], threshold=0.8, compliance_framework="EU_AI_ACT", )
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
create(demographic_parity=None, equalized_odds=None, disparate_impact_ratio=None, protected_attributes=None, group_metrics=None, threshold=0.8, phase='response', nonce=None, compliance_framework=None, control_id=None)
classmethod
Create a fairness metrics claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
demographic_parity
|
Optional[float]
|
Demographic parity score. |
None
|
equalized_odds
|
Optional[float]
|
Equalized odds score. |
None
|
disparate_impact_ratio
|
Optional[float]
|
80% rule ratio. |
None
|
protected_attributes
|
Optional[List[str]]
|
List of protected attributes evaluated. |
None
|
group_metrics
|
Optional[Dict[str, Dict[str, float]]]
|
Per-group metric breakdowns. |
None
|
threshold
|
float
|
Threshold for acceptable fairness. |
0.8
|
phase
|
str
|
Lifecycle phase. |
'response'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
compliance_framework
|
Optional[str]
|
Framework (EU_AI_ACT, CCPA_ADMT, etc.). |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
lucid_auditor_sdk.claim_types.WatermarkClaim
Factory for AI watermark/provenance claims.
Used by watermark auditor for EU AI Act Art.50 and other provenance requirements.
Example
claim = WatermarkClaim.create( watermark_embedded=True, watermark_type="statistical", detectable=True, compliance_framework="EU_AI_ACT", )
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
create(watermark_embedded, watermark_type=None, detectable=True, detection_score=None, c2pa_signed=False, phase='response', nonce=None, compliance_framework=None, control_id=None)
classmethod
Create a watermark/provenance claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
watermark_embedded
|
bool
|
Whether watermark was embedded. |
required |
watermark_type
|
Optional[str]
|
Type of watermark (statistical, c2pa, synthid). |
None
|
detectable
|
bool
|
Whether watermark is detectable. |
True
|
detection_score
|
Optional[float]
|
Detection confidence score. |
None
|
c2pa_signed
|
bool
|
Whether C2PA provenance was added. |
False
|
phase
|
str
|
Lifecycle phase. |
'response'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
lucid_auditor_sdk.claim_types.ModelSecurityClaim
Factory for model security claims.
Used by model-security auditor for artifact safety.
Example
claim = ModelSecurityClaim.create( format_valid=True, hash_verified=True, no_malware=True, provenance_verified=True, compliance_framework="EU_AI_ACT", )
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | |
create(format_valid, hash_verified, no_malware, provenance_verified, model_hash=None, format_type=None, vulnerabilities=None, phase='artifact', nonce=None, compliance_framework=None, control_id=None)
classmethod
Create a model security claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format_valid
|
bool
|
Whether model format is valid (safetensors). |
required |
hash_verified
|
bool
|
Whether hash matches manifest. |
required |
no_malware
|
bool
|
Whether scan found no malware. |
required |
provenance_verified
|
bool
|
Whether provenance signature is valid. |
required |
model_hash
|
Optional[str]
|
SHA-256 hash of model. |
None
|
format_type
|
Optional[str]
|
Model format (safetensors, pytorch, etc.). |
None
|
vulnerabilities
|
Optional[List[Dict[str, Any]]]
|
List of any vulnerabilities found. |
None
|
phase
|
str
|
Lifecycle phase. |
'artifact'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | |
lucid_auditor_sdk.claim_types.SovereigntyClaim
Factory for data sovereignty claims.
Used by sovereignty auditor for GDPR Art.44-49, India DPDP §17.
Example
claim = SovereigntyClaim.create( data_location="EU", allowed_locations=["EU", "US"], cross_border_transfer=False, compliant=True, compliance_framework="GDPR", )
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 | |
create(data_location, allowed_locations, cross_border_transfer=False, transfer_mechanism=None, compliant=True, user_jurisdiction=None, phase='request', nonce=None, compliance_framework=None, control_id=None)
classmethod
Create a data sovereignty claim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_location
|
str
|
Where data is being processed. |
required |
allowed_locations
|
List[str]
|
List of allowed processing locations. |
required |
cross_border_transfer
|
bool
|
Whether data crosses borders. |
False
|
transfer_mechanism
|
Optional[str]
|
Legal mechanism for transfer (SCC, adequacy, etc.). |
None
|
compliant
|
bool
|
Whether sovereignty rules are met. |
True
|
user_jurisdiction
|
Optional[str]
|
User's jurisdiction. |
None
|
phase
|
str
|
Lifecycle phase. |
'request'
|
nonce
|
Optional[str]
|
Optional anti-replay nonce. |
None
|
compliance_framework
|
Optional[str]
|
Framework (GDPR, DPDP, PIPL, etc.). |
None
|
Returns:
| Type | Description |
|---|---|
Claim
|
Claim instance. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 | |
Claim Categories
lucid_auditor_sdk.claim_types.ClaimCategory
Bases: str, Enum
Categories for audit claims.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/claim_types.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
Optional Import Utilities
Graceful degradation for optional dependencies without try/except boilerplate.
lucid_auditor_sdk.imports.optional_import(module_name, *, fallback=None, min_version=None, package_name=None, warn_on_missing=True, submodules=None)
Import a module optionally, returning a fallback if not available.
This function attempts to import a module and returns it if successful. If the import fails (e.g., module not installed), it returns either: - The provided fallback - A MockModule that logs warnings on access
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
The name of the module to import (e.g., "presidio_analyzer"). |
required |
fallback
|
Optional[Union[Type[T], Callable[[], T], Any]]
|
Optional fallback to return if import fails. Can be: - A class to instantiate - A callable that returns the fallback - Any other value to return directly |
None
|
min_version
|
Optional[str]
|
Optional minimum version string (e.g., "1.0.0"). |
None
|
package_name
|
Optional[str]
|
Optional PyPI package name if different from module name. |
None
|
warn_on_missing
|
bool
|
Whether to log a warning when the module is missing. |
True
|
submodules
|
Optional[List[str]]
|
Optional list of submodule names to also import. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The imported module, or the fallback/MockModule if import fails. |
Examples:
Basic usage
presidio = optional_import("presidio_analyzer") if presidio: analyzer = presidio.AnalyzerEngine()
With a fallback class
class MockDetector: def detect(self, text): return []
detector_lib = optional_import("detect_secrets", fallback=MockDetector) detector = detector_lib.Detector() if detector_lib else MockDetector()
With version requirement
torch = optional_import("torch", min_version="2.0.0")
Different package name
cv2 = optional_import("cv2", package_name="opencv-python")
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/imports.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
lucid_auditor_sdk.imports.OptionalDependency
Utility class for checking optional dependency availability.
Provides static methods for checking and managing optional dependencies.
Example
if OptionalDependency.is_available("presidio_analyzer"): from presidio_analyzer import AnalyzerEngine analyzer = AnalyzerEngine() else: analyzer = MockAnalyzer()
Get all available dependencies
available = OptionalDependency.list_available()
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/imports.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
get_version(module_name)
staticmethod
Get the version of an installed module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
The module to check. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Version string or None if not available. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/imports.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
is_available(module_name)
staticmethod
Check if a module is available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
The module to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the module is available and importable. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/imports.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
list_available()
staticmethod
List all available optional dependencies.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict mapping module names to their versions. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/imports.py
317 318 319 320 321 322 323 324 325 326 | |
list_missing()
staticmethod
List all missing optional dependencies.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict mapping module names to the reason they're missing. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/imports.py
328 329 330 331 332 333 334 335 336 337 338 339 | |
require(module_name, feature='this feature')
staticmethod
Require a module, raising an error if not available.
Use this when a feature absolutely requires a dependency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
The module that is required. |
required |
feature
|
str
|
Description of the feature that requires it. |
'this feature'
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the module is not available. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/imports.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
lucid_auditor_sdk.imports.requires_dependency(module_name, fallback_result=None, feature=None)
Decorator that makes a function require an optional dependency.
If the dependency is not available, the function either: - Returns the fallback_result (if provided) - Raises ImportError (if no fallback)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
The required module name. |
required |
fallback_result
|
Any
|
Value to return if dependency is missing. |
None
|
feature
|
Optional[str]
|
Description of the feature for error messages. |
None
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator function. |
Example
@requires_dependency("presidio_analyzer", fallback_result=[]) def detect_pii(text: str) -> List[dict]: from presidio_analyzer import AnalyzerEngine analyzer = AnalyzerEngine() results = analyzer.analyze(text=text, language="en") return [r.to_dict() for r in results]
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/imports.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
Pre-defined Fallbacks
These fallback configurations are available for common auditor dependencies:
| Fallback | Package | Description |
|---|---|---|
FALLBACK_PRESIDIO |
presidio_analyzer |
PII detection |
FALLBACK_LLM_GUARD |
llm_guard |
Input/output guardrails |
FALLBACK_DETECT_SECRETS |
detect_secrets |
Secret detection |
FALLBACK_FAIRLEARN |
fairlearn |
Fairness metrics |
FALLBACK_RAGAS |
ragas |
RAG evaluation |
Testing Utilities
The lucid_auditor_sdk.testing module provides shared fixtures and helpers for ClaimsAuditor testing.
Pytest Fixtures
# In conftest.py
from lucid_auditor_sdk.testing import pytest_plugins
# Or import specific fixtures
from lucid_auditor_sdk.testing import (
mock_config,
mock_http_factory,
test_client,
sample_request_data,
sample_response_data,
)
lucid_auditor_sdk.testing.fixtures.MockConfig
dataclass
Mock configuration for testing auditors.
Provides default values that work for most test scenarios.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
__getattr__(name)
Allow accessing any attribute (returns None for undefined).
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
63 64 65 | |
lucid_auditor_sdk.testing.fixtures.MockHTTPClientFactory
Mock HTTP client factory for testing without network calls.
All HTTP operations are mocked and can be inspected.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
close()
async
Mock close - no-op.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
86 87 88 | |
get_client()
async
Return a mock HTTP client.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
82 83 84 | |
post_with_retry(url, json_data, max_retries=3, timeout=None)
async
Mock POST with retry - records call and returns mock response.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
reset()
Reset all recorded calls.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
136 137 138 139 | |
submit_evidence(auditor_id, model_id, session_id, nonce, decision, metadata, phase='request')
async
Mock evidence submission - records call and returns success.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
lucid_auditor_sdk.testing.fixtures.MockAuditor
Mock claims-based auditor for testing endpoints.
Produces configurable claims for each phase, following the ClaimsAuditor contract where auditors return list[Claim].
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
reset()
Reset all recorded calls and claim responses.
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
205 206 207 208 209 210 211 212 213 214 | |
Test Data Generators
lucid_auditor_sdk.testing.helpers.generate_pii_text(*, include_ssn=True, include_email=True, include_phone=False, include_credit_card=False, include_address=False, include_name=False, context='general')
Generate text containing PII for testing PII detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_ssn
|
bool
|
Include a Social Security Number. |
True
|
include_email
|
bool
|
Include an email address. |
True
|
include_phone
|
bool
|
Include a phone number. |
False
|
include_credit_card
|
bool
|
Include a credit card number. |
False
|
include_address
|
bool
|
Include a street address. |
False
|
include_name
|
bool
|
Include a person's name. |
False
|
context
|
str
|
Context for the text (general, medical, financial). |
'general'
|
Returns:
| Type | Description |
|---|---|
str
|
Text string containing the specified PII types. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/helpers.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
lucid_auditor_sdk.testing.helpers.generate_toxic_text(category='general', severity='medium')
Generate text with toxic content for testing toxicity detection.
Note: This generates mild test cases suitable for automated testing. Real toxic content detection should be tested with curated datasets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str
|
Category of toxicity (general, harassment, profanity). |
'general'
|
severity
|
str
|
Severity level (low, medium, high). |
'medium'
|
Returns:
| Type | Description |
|---|---|
str
|
Text string with toxic content indicators. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/helpers.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
lucid_auditor_sdk.testing.helpers.generate_injection_text(injection_type='direct', include_payload=True)
Generate text with injection patterns for testing injection detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
injection_type
|
str
|
Type of injection (direct, indirect, jailbreak, encoding). |
'direct'
|
include_payload
|
bool
|
Whether to include a payload after the injection. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Text string with injection patterns. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/helpers.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
lucid_auditor_sdk.testing.helpers.generate_secret_text(secret_type='api_key', context='code')
Generate text containing secrets for testing secret detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
secret_type
|
str
|
Type of secret (api_key, aws_key, github_token, password). |
'api_key'
|
context
|
str
|
Context (code, config, message). |
'code'
|
Returns:
| Type | Description |
|---|---|
str
|
Text string containing secret patterns. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/helpers.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
lucid_auditor_sdk.testing.helpers.generate_clean_text(length='medium', topic='general')
Generate clean text with no safety issues for testing false positives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
str
|
Length of text (short, medium, long). |
'medium'
|
topic
|
str
|
Topic of text (general, technical, casual). |
'general'
|
Returns:
| Type | Description |
|---|---|
str
|
Clean text string that should not trigger any detections. |
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/helpers.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
Assertion Helpers
from lucid_auditor_sdk.testing import assert_claims_result, assert_claim_value
def test_detects_injection():
auditor = InjectionAuditor()
claims = auditor.detect_injection({"prompt": "Ignore all instructions"})
assert_claims_result(claims, "injection_risk")
assert_claim_value(claims, "injection_risk", 0.9)
lucid_auditor_sdk.testing.fixtures.assert_claims_result(claims_list, expected_claim_name=None, min_claims=0)
Assert a claims result is well-formed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
claims_list
|
Any
|
The list of claims to check (list[Claim] or list[dict]). |
required |
expected_claim_name
|
Optional[str]
|
Optional claim name that must be present. |
None
|
min_claims
|
int
|
Minimum number of claims expected. |
0
|
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
lucid_auditor_sdk.testing.fixtures.assert_claim_value(claims_list, claim_name, expected_value=None, min_confidence=None)
Assert a specific claim has the expected value and confidence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
claims_list
|
Any
|
The list of claims to search. |
required |
claim_name
|
str
|
Name of the claim to find. |
required |
expected_value
|
Any
|
Optional expected value for the claim. |
None
|
min_confidence
|
Optional[float]
|
Optional minimum confidence threshold. |
None
|
Source code in packages/external/lucid-auditor-sdk/lucid_auditor_sdk/testing/fixtures.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
WASM Crypto Modules
The SDK delegates cryptographic operations to sandboxed WASM modules from the packages/internal/lucid-wasm/ workspace.
ReceiptChain
The receipt chain provides a tamper-evident audit trail by hash-linking every request/response interaction.
from lucid_auditor_sdk._wasm.receipt import ReceiptChain, hash_data
# Create a receipt chain (Ed25519 keypair generated inside WASM sandbox)
chain = ReceiptChain(attestation_hash="sha256:abc123...")
# Create a chained receipt
receipt = chain.create_receipt(
request_hash=hash_data(b"request content"),
response_hash=hash_data(b"response content"),
tool=None,
verdict="allow",
latency_ms=42,
claims_hash="sha256:...",
cedar_decision="allow",
cedar_policy_hash="sha256:...",
auditor_ids=["guardrails", "pii"],
claim_count=5,
)
# Verify chain integrity
verification = chain.verify()
# verification.chain_intact: bool
# verification.total_receipts: int
# verification.first_seq: int
# verification.last_seq: int
# Export/import for pod restart recovery
data = chain.export_chain()
restored = ReceiptChain.import_chain(data, attestation_hash="sha256:abc123...")
hash_data
Hash arbitrary data using the same SHA-256 implementation used for receipt hashing.
from lucid_auditor_sdk._wasm.receipt import hash_data
content_hash = hash_data(b"content to hash") # returns hex-encoded SHA-256
SDK
The Python SDK (packages/external/lucid-auditor-sdk/) wraps the .wasm binary compiled from the packages/internal/lucid-wasm/ Rust workspace. The WASM binary contains the Ed25519 signing key, SHA-256 hashing, and receipt chain logic inside a sandbox with no filesystem, network, or syscall access.
| Language | Package | WASM Runtime | Package Manager | Status |
|---|---|---|---|---|
| Python | packages/external/lucid-auditor-sdk/ |
wasmtime-py (pure-Python fallback) | pip | Production |
The SDK exposes these core interfaces generated from the WIT (WASM Interface Type) definitions:
- ReceiptChain: Hash-linked tamper-evident audit trail
- hash_data: SHA-256 hashing (same algorithm as receipt chain)
- KeyManager: AES-256-GCM encryption (from
lucid-wasm-encrypt) - CedarEvaluator: Sandboxed Cedar policy evaluation (from
lucid-wasm-cedar)
All language SDKs run conformance tests against a shared test_vectors.json to ensure identical behavior across runtimes.