llmfirewall-core 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. llmfirewall/__init__.py +1041 -0
  2. llmfirewall/_version.py +3 -0
  3. llmfirewall/attack_graph/__init__.py +76 -0
  4. llmfirewall/attack_graph/engine.py +907 -0
  5. llmfirewall/attack_graph/models.py +376 -0
  6. llmfirewall/attack_graph/reporting.py +224 -0
  7. llmfirewall/attack_graph/rules.py +397 -0
  8. llmfirewall/attack_graph/techniques.py +144 -0
  9. llmfirewall/audit.py +99 -0
  10. llmfirewall/capabilities/__init__.py +55 -0
  11. llmfirewall/capabilities/approval.py +89 -0
  12. llmfirewall/capabilities/budget.py +72 -0
  13. llmfirewall/capabilities/engine.py +543 -0
  14. llmfirewall/capabilities/models.py +208 -0
  15. llmfirewall/cli/__init__.py +5 -0
  16. llmfirewall/cli/__main__.py +7 -0
  17. llmfirewall/cli/commands.py +3437 -0
  18. llmfirewall/cli/errors.py +12 -0
  19. llmfirewall/cli/formatting.py +126 -0
  20. llmfirewall/cli/main.py +1488 -0
  21. llmfirewall/compliance/__init__.py +91 -0
  22. llmfirewall/compliance/catalog.py +588 -0
  23. llmfirewall/compliance/engine.py +981 -0
  24. llmfirewall/compliance/models.py +513 -0
  25. llmfirewall/compliance/reporting.py +277 -0
  26. llmfirewall/compliance/rules.py +421 -0
  27. llmfirewall/config/__init__.py +29 -0
  28. llmfirewall/config/models.py +427 -0
  29. llmfirewall/core/__init__.py +49 -0
  30. llmfirewall/core/exceptions.py +27 -0
  31. llmfirewall/core/interfaces.py +57 -0
  32. llmfirewall/core/models.py +283 -0
  33. llmfirewall/detectors/__init__.py +24 -0
  34. llmfirewall/detectors/base.py +45 -0
  35. llmfirewall/detectors/collection.py +55 -0
  36. llmfirewall/detectors/engine.py +86 -0
  37. llmfirewall/detectors/examples.py +55 -0
  38. llmfirewall/detectors/metadata.py +28 -0
  39. llmfirewall/detectors/pii/__init__.py +26 -0
  40. llmfirewall/detectors/pii/detector.py +144 -0
  41. llmfirewall/detectors/pii/sub_detectors.py +285 -0
  42. llmfirewall/detectors/pii/validators.py +40 -0
  43. llmfirewall/detectors/prompt_injection/__init__.py +27 -0
  44. llmfirewall/detectors/prompt_injection/analyzer.py +80 -0
  45. llmfirewall/detectors/prompt_injection/detector.py +82 -0
  46. llmfirewall/detectors/prompt_injection/normalizer.py +40 -0
  47. llmfirewall/detectors/prompt_injection/rules.py +375 -0
  48. llmfirewall/detectors/registry.py +59 -0
  49. llmfirewall/detectors/secrets/__init__.py +23 -0
  50. llmfirewall/detectors/secrets/detector.py +121 -0
  51. llmfirewall/detectors/secrets/entropy.py +24 -0
  52. llmfirewall/detectors/secrets/rules.py +320 -0
  53. llmfirewall/eval/__init__.py +145 -0
  54. llmfirewall/eval/adapters.py +439 -0
  55. llmfirewall/eval/assertions.py +164 -0
  56. llmfirewall/eval/engine.py +64 -0
  57. llmfirewall/eval/generators.py +315 -0
  58. llmfirewall/eval/mock_tools.py +106 -0
  59. llmfirewall/eval/models.py +299 -0
  60. llmfirewall/eval/orchestrator.py +489 -0
  61. llmfirewall/eval/payloads.py +336 -0
  62. llmfirewall/eval/reporting.py +363 -0
  63. llmfirewall/eval/suites.py +529 -0
  64. llmfirewall/eval/targets.py +130 -0
  65. llmfirewall/firewall.py +1385 -0
  66. llmfirewall/governance/__init__.py +81 -0
  67. llmfirewall/governance/baseline.py +246 -0
  68. llmfirewall/governance/decisions.py +103 -0
  69. llmfirewall/governance/engine.py +982 -0
  70. llmfirewall/governance/evidence.py +108 -0
  71. llmfirewall/governance/findings.py +132 -0
  72. llmfirewall/governance/gates.py +75 -0
  73. llmfirewall/governance/manifest.py +126 -0
  74. llmfirewall/governance/policy.py +260 -0
  75. llmfirewall/governance/reporting.py +177 -0
  76. llmfirewall/governance/waivers.py +190 -0
  77. llmfirewall/graph/__init__.py +69 -0
  78. llmfirewall/graph/engine.py +1126 -0
  79. llmfirewall/graph/models.py +391 -0
  80. llmfirewall/graph/reporting.py +207 -0
  81. llmfirewall/graph/stores/__init__.py +11 -0
  82. llmfirewall/graph/stores/base.py +85 -0
  83. llmfirewall/graph/stores/memory.py +188 -0
  84. llmfirewall/graph/stores/sqlite.py +307 -0
  85. llmfirewall/incidents/__init__.py +62 -0
  86. llmfirewall/incidents/manager.py +500 -0
  87. llmfirewall/incidents/models.py +234 -0
  88. llmfirewall/incidents/reporting.py +239 -0
  89. llmfirewall/incidents/rules.py +365 -0
  90. llmfirewall/integrations/__init__.py +78 -0
  91. llmfirewall/integrations/base.py +191 -0
  92. llmfirewall/integrations/django.py +132 -0
  93. llmfirewall/integrations/fastapi/__init__.py +50 -0
  94. llmfirewall/integrations/fastapi/exceptions.py +25 -0
  95. llmfirewall/integrations/fastapi/extraction.py +61 -0
  96. llmfirewall/integrations/fastapi/helpers.py +139 -0
  97. llmfirewall/integrations/fastapi/middleware.py +228 -0
  98. llmfirewall/integrations/fastapi/responses.py +67 -0
  99. llmfirewall/integrations/flask.py +167 -0
  100. llmfirewall/integrations/langchain.py +195 -0
  101. llmfirewall/integrations/llamaindex.py +100 -0
  102. llmfirewall/inventory/__init__.py +79 -0
  103. llmfirewall/inventory/engine.py +884 -0
  104. llmfirewall/inventory/models.py +433 -0
  105. llmfirewall/inventory/providers/__init__.py +21 -0
  106. llmfirewall/inventory/providers/base.py +22 -0
  107. llmfirewall/inventory/providers/code.py +151 -0
  108. llmfirewall/inventory/providers/config.py +297 -0
  109. llmfirewall/inventory/providers/dependencies.py +98 -0
  110. llmfirewall/inventory/providers/env.py +98 -0
  111. llmfirewall/inventory/providers/import_provider.py +115 -0
  112. llmfirewall/inventory/providers/manual.py +25 -0
  113. llmfirewall/inventory/providers/runtime.py +164 -0
  114. llmfirewall/inventory/reporting.py +197 -0
  115. llmfirewall/observability/__init__.py +52 -0
  116. llmfirewall/observability/exporters.py +125 -0
  117. llmfirewall/observability/intelligence.py +379 -0
  118. llmfirewall/observability/models.py +406 -0
  119. llmfirewall/observability/store.py +465 -0
  120. llmfirewall/policy/__init__.py +33 -0
  121. llmfirewall/policy/config.py +334 -0
  122. llmfirewall/policy/engine.py +210 -0
  123. llmfirewall/policy/redaction_config.py +45 -0
  124. llmfirewall/policy/redactor.py +100 -0
  125. llmfirewall/protection/__init__.py +50 -0
  126. llmfirewall/protection/engine.py +463 -0
  127. llmfirewall/protection/models.py +121 -0
  128. llmfirewall/protection/policy.py +183 -0
  129. llmfirewall/protection/rate_limiter.py +67 -0
  130. llmfirewall/protection/sdk.py +170 -0
  131. llmfirewall/rag/__init__.py +32 -0
  132. llmfirewall/rag/cache.py +66 -0
  133. llmfirewall/rag/ingestion.py +200 -0
  134. llmfirewall/rag/memory.py +103 -0
  135. llmfirewall/rag/models.py +125 -0
  136. llmfirewall/rag/orchestrator.py +246 -0
  137. llmfirewall/risk/__init__.py +46 -0
  138. llmfirewall/risk/config.py +67 -0
  139. llmfirewall/risk/engine.py +219 -0
  140. llmfirewall/risk/models.py +181 -0
  141. llmfirewall/risk/prioritizer.py +481 -0
  142. llmfirewall/risk/reporting.py +121 -0
  143. llmfirewall/runtime/__init__.py +46 -0
  144. llmfirewall/runtime/adapters.py +159 -0
  145. llmfirewall/runtime/engine.py +191 -0
  146. llmfirewall/runtime/guard.py +166 -0
  147. llmfirewall/runtime/hooks.py +176 -0
  148. llmfirewall/runtime/models.py +235 -0
  149. llmfirewall/runtime/session.py +543 -0
  150. llmfirewall/spm/__init__.py +64 -0
  151. llmfirewall/spm/engine.py +866 -0
  152. llmfirewall/spm/models.py +375 -0
  153. llmfirewall/spm/reporting.py +320 -0
  154. llmfirewall/spm/rules.py +467 -0
  155. llmfirewall/supply_chain/__init__.py +90 -0
  156. llmfirewall/supply_chain/dependencies.py +240 -0
  157. llmfirewall/supply_chain/guard.py +134 -0
  158. llmfirewall/supply_chain/integrity.py +180 -0
  159. llmfirewall/supply_chain/manifest.py +189 -0
  160. llmfirewall/supply_chain/models.py +347 -0
  161. llmfirewall/supply_chain/verifier.py +365 -0
  162. llmfirewall/telemetry/__init__.py +16 -0
  163. llmfirewall/telemetry/events.py +166 -0
  164. llmfirewall/telemetry/exporters/logging.py +98 -0
  165. llmfirewall/telemetry/metrics.py +103 -0
  166. llmfirewall/telemetry/sink.py +51 -0
  167. llmfirewall/tools/__init__.py +47 -0
  168. llmfirewall/tools/command_security.py +76 -0
  169. llmfirewall/tools/engine.py +404 -0
  170. llmfirewall/tools/models.py +138 -0
  171. llmfirewall/tools/path_security.py +128 -0
  172. llmfirewall/tools/registry.py +111 -0
  173. llmfirewall/tools/url_security.py +187 -0
  174. llmfirewall/tools/validator.py +159 -0
  175. llmfirewall_core-1.0.0.dist-info/METADATA +379 -0
  176. llmfirewall_core-1.0.0.dist-info/RECORD +179 -0
  177. llmfirewall_core-1.0.0.dist-info/WHEEL +4 -0
  178. llmfirewall_core-1.0.0.dist-info/entry_points.txt +2 -0
  179. llmfirewall_core-1.0.0.dist-info/licenses/LICENSE +176 -0
@@ -0,0 +1,1041 @@
1
+ """LLMFirewall: A lightweight, provider-agnostic security layer for LLMs."""
2
+
3
+ from typing import Any, Optional
4
+
5
+ from llmfirewall.core.exceptions import (
6
+ BlockedOutputError,
7
+ BlockedPromptError,
8
+ ConfigurationError,
9
+ LLMFirewallError,
10
+ )
11
+ from llmfirewall.core.interfaces import (
12
+ BaseDetector,
13
+ BasePolicyEngine,
14
+ BaseRiskEngine,
15
+ )
16
+ from llmfirewall.core.models import (
17
+ Action,
18
+ AuditEvent,
19
+ DecisionAction,
20
+ Finding,
21
+ FirewallResult,
22
+ MAX_SCAN_TEXT_LENGTH,
23
+ PolicyDecision,
24
+ RiskScore,
25
+ ScanRequest,
26
+ ScanResult,
27
+ Severity,
28
+ ThreatType,
29
+ )
30
+ from llmfirewall.detectors.base import Detector
31
+ from llmfirewall.detectors.collection import FindingCollection
32
+ from llmfirewall.detectors.engine import DetectorEngine
33
+ from llmfirewall.detectors.examples import KeywordDetector
34
+ from llmfirewall.detectors.metadata import DetectorMetadata
35
+ from llmfirewall.detectors.pii import PIIDetector
36
+ from llmfirewall.detectors.prompt_injection import PromptInjectionDetector
37
+ from llmfirewall.detectors.registry import DetectorRegistry, default_detector_registry
38
+ from llmfirewall.config.models import (
39
+ AgentCapabilitiesConfig,
40
+ AuditConfig,
41
+ ContextBudgetConfig,
42
+ DependencySecurityConfig,
43
+ DetectorConfig,
44
+ FirewallConfig,
45
+ IngestionConfig,
46
+ IntegrationsConfig,
47
+ ModelSecurityConfig,
48
+ ObservabilityConfig,
49
+ PIIConfig,
50
+ PromptInjectionConfig,
51
+ RAGConfig,
52
+ RuntimeConfig,
53
+ RuntimeLimitsConfig,
54
+ SecretConfig,
55
+ SupplyChainConfig,
56
+ TelemetryConfig,
57
+ )
58
+ from llmfirewall.supply_chain import (
59
+ ConfigArtifact,
60
+ DependencyArtifact,
61
+ DependencyScanner,
62
+ DependencyScope,
63
+ DependencySourceType,
64
+ DeploymentMetadata,
65
+ IntegrityManager,
66
+ IntegrityResult,
67
+ IntegrityStatus,
68
+ ModelApprovalStatus,
69
+ ModelArtifact,
70
+ ModelFormat,
71
+ ModelLoadingGuard,
72
+ ModelManifest,
73
+ ModelProvenance,
74
+ ModelSecurityDecision,
75
+ ModelSecurityRegistry,
76
+ ModelSourceType,
77
+ ModelTrustLevel,
78
+ ModelVerifier,
79
+ OfflineVulnerabilityProvider,
80
+ PolicyArtifact,
81
+ PromptArtifact,
82
+ SecuritySnapshot,
83
+ SnapshotDiff,
84
+ VulnerabilityFinding,
85
+ VulnerabilityProvider,
86
+ compute_streaming_hash,
87
+ detect_model_format,
88
+ hash_configuration,
89
+ hash_policy_artifact,
90
+ hash_prompt_artifact,
91
+ is_unsafe_serialization,
92
+ sanitize_config_dict,
93
+ )
94
+ from llmfirewall.capabilities import (
95
+ ActionBudget,
96
+ ActionChain,
97
+ ActionClassification,
98
+ ActionDecision,
99
+ ActionDecisionStatus,
100
+ ActionRequest,
101
+ ApprovalProvider,
102
+ ApprovalRequest,
103
+ BudgetManager,
104
+ CallbackApprovalProvider,
105
+ Capability,
106
+ CapabilityEngine,
107
+ CapabilityGrant,
108
+ CapabilityRiskClass,
109
+ DEFAULT_CAPABILITIES,
110
+ DEFAULT_TOOL_CAPABILITY_MAP,
111
+ DelegationGrant,
112
+ DenyAllApprovalProvider,
113
+ MemoryApprovalProvider,
114
+ SideEffectType,
115
+ )
116
+ from llmfirewall.rag import (
117
+ CitationValidator,
118
+ ContextItem,
119
+ ContextOrchestrator,
120
+ ContextSecurityDecision,
121
+ DocumentIngestionResult,
122
+ DocumentIngestionScanner,
123
+ DocumentSecurityStatus,
124
+ InstructionAuthority,
125
+ MemorySecurityGuard,
126
+ QuarantineStore,
127
+ SecurityScanCache,
128
+ SourceProvenance,
129
+ )
130
+ from llmfirewall.integrations import (
131
+ FirewallIntegration,
132
+ IntegrationRegistry,
133
+ SecurityViolation,
134
+ protect,
135
+ )
136
+ from llmfirewall.runtime import (
137
+ ContentItem,
138
+ GenericProviderAdapter,
139
+ HookPipeline,
140
+ LLMMessage,
141
+ LLMProviderAdapter,
142
+ LLMRequest,
143
+ LLMResponse,
144
+ LoopGuard,
145
+ RuntimeBoundary,
146
+ RuntimeContext,
147
+ RuntimeDecision,
148
+ RuntimeEngine,
149
+ RuntimeEventType,
150
+ RuntimeHook,
151
+ RuntimeLimitExceeded,
152
+ RuntimeSecurityError,
153
+ RuntimeSecurityState,
154
+ RuntimeSession,
155
+ TrustLevel,
156
+ )
157
+ from llmfirewall.observability import (
158
+ AnomalyEvent,
159
+ DecisionTrace,
160
+ DecisionTraceStep,
161
+ EventFilter,
162
+ EventSeverity,
163
+ EventStore,
164
+ InMemoryEventStore,
165
+ JSONLEventStore,
166
+ SQLiteEventStore,
167
+ SecurityEvent,
168
+ SecurityEventType,
169
+ SecurityIntelligenceEngine,
170
+ export_events_csv,
171
+ export_events_json,
172
+ export_events_jsonl,
173
+ export_prometheus_metrics,
174
+ hash_content,
175
+ )
176
+ from llmfirewall.detectors.secrets import SecretDetector
177
+ from llmfirewall.firewall import Firewall
178
+ from llmfirewall.policy.config import (
179
+ LogicalOperator,
180
+ Policy,
181
+ PolicyConfig,
182
+ PolicyRule,
183
+ PolicyValidationError,
184
+ RuleCondition,
185
+ )
186
+ from llmfirewall.policy.engine import ACTION_PRECEDENCE, PolicyEngine, get_default_policy
187
+ from llmfirewall.policy.redaction_config import RedactionConfig
188
+ from llmfirewall.policy.redactor import SafeRedactor, default_redactor, redact_text_spans
189
+ from llmfirewall.audit import AuditLogger, default_audit_logger
190
+ from llmfirewall.telemetry import (
191
+ InMemoryTelemetrySink,
192
+ MetricSummary,
193
+ MetricsCollector,
194
+ NoOpTelemetry,
195
+ TelemetryEvent,
196
+ TelemetryEventType,
197
+ TelemetrySink,
198
+ )
199
+ from llmfirewall.risk.config import RiskConfig
200
+ from llmfirewall.risk.engine import RiskEngine
201
+ from llmfirewall.tools import (
202
+ ArgumentLimits,
203
+ ToolCall,
204
+ ToolDefinition,
205
+ ToolPermission,
206
+ ToolRegistry,
207
+ ToolResult,
208
+ ToolSecurityDecision,
209
+ ToolSecurityEngine,
210
+ default_tool_registry,
211
+ inspect_command_safety,
212
+ inspect_sql_safety,
213
+ validate_argument_limits,
214
+ validate_json_schema,
215
+ validate_path_safety,
216
+ validate_url_safety,
217
+ )
218
+ from llmfirewall.eval import (
219
+ AgentAdapter,
220
+ AgentCapabilityGenerator,
221
+ AssertionType,
222
+ AttackCategory,
223
+ BoundedFuzzer,
224
+ BUILTIN_SUITES,
225
+ CallableAdapter,
226
+ DeclarativeAssertion,
227
+ ErrorCategory,
228
+ EvaluationTarget,
229
+ FirewallAdapter,
230
+ FirewallTarget,
231
+ HTTPTargetAdapter,
232
+ MockAdapter,
233
+ MockToolRegistry,
234
+ PIIGenerator,
235
+ PromptInjectionGenerator,
236
+ RAGAdapter,
237
+ RAGPoisoningGenerator,
238
+ SecretGenerator,
239
+ SecurityCoverage,
240
+ SecurityDetectionCoverage,
241
+ SecurityEvaluationEngine,
242
+ SecurityEvaluationReport,
243
+ SecurityFinding,
244
+ SecurityMetrics,
245
+ SecurityObservation,
246
+ SecurityTest,
247
+ SecurityTestCase,
248
+ SecurityTestGenerator,
249
+ SecurityTestResult,
250
+ SecurityTestSuite,
251
+ TargetAdapter,
252
+ TargetType,
253
+ TestOrchestrator,
254
+ TestStatus,
255
+ ToolSecurityGenerator,
256
+ create_mutations,
257
+ evaluate_assertion,
258
+ evaluate_assertions,
259
+ format_html_report,
260
+ format_human_report,
261
+ format_json_report,
262
+ format_junit_report,
263
+ format_sarif_report,
264
+ get_agent_capability_suite,
265
+ get_builtin_security_test_cases,
266
+ get_configuration_integrity_suite,
267
+ get_core_firewall_suite,
268
+ get_full_red_team_suite,
269
+ get_memory_security_suite,
270
+ get_pii_suite,
271
+ get_prompt_injection_suite,
272
+ get_rag_security_suite,
273
+ get_regression_suite,
274
+ get_secret_suite,
275
+ get_supply_chain_suite,
276
+ get_tool_security_suite,
277
+ )
278
+ from llmfirewall.governance import (
279
+ BaselineCategory,
280
+ BaselineDiff,
281
+ EvidenceArtifactRecord,
282
+ EvidenceManifest,
283
+ FindingStatus,
284
+ GateEvaluationResult,
285
+ GateType,
286
+ GovernanceDecision,
287
+ GovernanceEngine,
288
+ GovernanceFinding,
289
+ GovernanceMetrics,
290
+ GovernanceOverride,
291
+ GovernancePolicy,
292
+ GovernanceResult,
293
+ ReasonCode,
294
+ ReleaseProfile,
295
+ SecurityBaseline,
296
+ SecurityChangeClassification,
297
+ SecurityEvidence,
298
+ SecurityGate,
299
+ SecurityGateFailure,
300
+ SecurityReleaseManifest,
301
+ SecurityWaiver,
302
+ format_governance_human,
303
+ format_governance_json,
304
+ format_governance_sarif,
305
+ )
306
+ from llmfirewall.graph import (
307
+ BlastRadiusResult,
308
+ ControlCoverageItem,
309
+ ControlCoverageResult,
310
+ ControlStatus,
311
+ GraphDiff,
312
+ GraphMetrics,
313
+ GraphPath,
314
+ GraphSnapshot,
315
+ GraphStore,
316
+ InMemoryGraphStore,
317
+ KnowledgeGraph,
318
+ Node,
319
+ NodeType,
320
+ Relationship,
321
+ RelationshipType,
322
+ SQLiteGraphStore,
323
+ SecurityDiff,
324
+ SecurityImpactResult,
325
+ format_blast_radius_human,
326
+ format_coverage_human,
327
+ format_graph_diff_human,
328
+ format_impact_human,
329
+ format_node_show_human,
330
+ format_path_human,
331
+ )
332
+ from llmfirewall.attack_graph import (
333
+ AttackEvidence,
334
+ AttackGraph,
335
+ AttackGraphDiff,
336
+ AttackGraphMetrics,
337
+ AttackGraphSnapshot,
338
+ AttackNode,
339
+ AttackPath,
340
+ AttackRule,
341
+ AttackRuleRegistry,
342
+ AttackStep,
343
+ AttackTechnique,
344
+ AttackTechniqueRegistry,
345
+ ConfidenceLevel,
346
+ ControlEffectiveness,
347
+ EntryPoint,
348
+ EntryPointType,
349
+ EvidenceType,
350
+ MitigationStatus,
351
+ PathStatus,
352
+ PreconditionEvaluator,
353
+ STANDARD_RULES,
354
+ ThreatModel,
355
+ TrustBoundary,
356
+ default_technique_registry,
357
+ format_attack_graph_sarif,
358
+ format_attack_paths_human,
359
+ format_attack_paths_json,
360
+ format_threat_model_human,
361
+ )
362
+ from llmfirewall.inventory import (
363
+ Asset,
364
+ AssetConflict,
365
+ AssetExposure,
366
+ AssetInventory,
367
+ AssetProvenance,
368
+ AssetSource,
369
+ AssetStatus,
370
+ AssetType,
371
+ CodeDiscoveryProvider,
372
+ ConfigDiscoveryProvider,
373
+ DependencyDiscoveryProvider,
374
+ DiscoveryConfidence,
375
+ DiscoveryEngine,
376
+ DiscoveryProvider,
377
+ DiscoveryResult,
378
+ DiscoveryStatus,
379
+ EnvironmentDiscoveryProvider,
380
+ ImportDiscoveryProvider,
381
+ InventoryDiff,
382
+ InventoryMetrics,
383
+ InventorySnapshot,
384
+ ManualDiscoveryProvider,
385
+ RuntimeDiscoveryProvider,
386
+ format_asset_show_human,
387
+ format_discovery_result_human,
388
+ format_discovery_result_json,
389
+ format_inventory_diff_human,
390
+ format_inventory_json,
391
+ format_inventory_list_human,
392
+ normalize_asset_id,
393
+ sanitize_metadata_secrets,
394
+ )
395
+ from llmfirewall.spm import (
396
+ AttackSurfaceRecord,
397
+ ControlPostureRecord,
398
+ ControlPresence,
399
+ PostureDiff,
400
+ PostureDimension,
401
+ PostureEngine,
402
+ PostureMetrics,
403
+ PostureRule,
404
+ PostureRuleContext,
405
+ PostureRuleRegistry,
406
+ PostureSnapshot,
407
+ PostureState,
408
+ SecurityGap,
409
+ SecurityGapStatus,
410
+ SecurityPosture,
411
+ TestCoverageRecord,
412
+ TestFreshness,
413
+ format_posture_diff_human,
414
+ format_posture_human,
415
+ format_posture_json,
416
+ format_posture_sarif,
417
+ format_posture_summary_human,
418
+ sanitize_posture_metadata,
419
+ )
420
+ from llmfirewall.compliance import (
421
+ AI_SECURITY_BASELINE_CONTROLS,
422
+ ApplicabilityStatus,
423
+ ComplianceControl,
424
+ ComplianceDiff,
425
+ ComplianceEngine,
426
+ ComplianceEvidence,
427
+ ComplianceException,
428
+ ComplianceFramework,
429
+ ComplianceGap,
430
+ ComplianceMetrics,
431
+ ComplianceRule,
432
+ ComplianceRuleContext,
433
+ ComplianceRuleRegistry,
434
+ ComplianceSnapshot,
435
+ ControlAssessment,
436
+ ControlCatalog,
437
+ ControlMapping,
438
+ ControlState,
439
+ CrossFrameworkMapping,
440
+ ComplianceEvidenceType,
441
+ EvidenceValidity,
442
+ ExceptionStatus,
443
+ MappingType,
444
+ RemediationStatus,
445
+ STANDARD_COMPLIANCE_RULES,
446
+ format_compliance_human,
447
+ format_compliance_json,
448
+ format_compliance_yaml,
449
+ format_control_detail_human,
450
+ format_diff_human,
451
+ format_evidence_human,
452
+ format_gaps_human,
453
+ sanitize_compliance_metadata,
454
+ )
455
+ from llmfirewall.risk import (
456
+ RiskAssessment,
457
+ RiskDiff,
458
+ RiskFactor,
459
+ RiskFactorType,
460
+ RiskHistoryEntry,
461
+ RiskLevel,
462
+ RiskPrioritizationEngine,
463
+ RiskSnapshot,
464
+ RiskTreatment,
465
+ RiskUncertainty,
466
+ format_risk_detail_human,
467
+ format_risk_diff_human,
468
+ format_risk_human,
469
+ format_risk_json,
470
+ format_risk_yaml,
471
+ )
472
+ from llmfirewall.incidents import (
473
+ AbnormalAgentBehaviorRule,
474
+ EvidenceItem,
475
+ IncidentAction,
476
+ IncidentActionRecord,
477
+ IncidentCandidate,
478
+ IncidentDetectionRule,
479
+ IncidentError,
480
+ IncidentManager,
481
+ IncidentSeverity,
482
+ IncidentStatus,
483
+ PolicyBypassRule,
484
+ PromptInjectionFollowedByPrivilegedToolRule,
485
+ RepeatedUnauthorizedToolCallsRule,
486
+ SecretExposureRule,
487
+ SecurityEvent,
488
+ SecurityEventType,
489
+ SecurityIncident,
490
+ TimelineEntry,
491
+ compute_evidence_hash,
492
+ format_incident_detail_human,
493
+ format_incident_timeline_human,
494
+ format_incidents_table_human,
495
+ generate_post_incident_report,
496
+ get_default_incident_rules,
497
+ )
498
+ from llmfirewall.protection import (
499
+ FailBehavior,
500
+ LLMFirewallMiddleware,
501
+ PolicyDecision,
502
+ PolicyMode,
503
+ ProtectionAuditEntry,
504
+ ProtectionPolicy,
505
+ ProtectionRule,
506
+ RateLimitRule,
507
+ RateLimiter,
508
+ ProtectionCondition,
509
+ RuntimeDecision,
510
+ RuntimeProtectionEngine,
511
+ RuntimeRequest,
512
+ SecurityBlockError,
513
+ get_default_production_policy,
514
+ protect,
515
+ protect_tool,
516
+ )
517
+ from llmfirewall._version import __version__
518
+
519
+
520
+ class Scanner:
521
+ """Convenience public scanner class for analyzing inputs and requests."""
522
+
523
+ def __init__(self, firewall: Optional[Firewall] = None) -> None:
524
+ self.firewall = firewall or Firewall()
525
+
526
+ def scan(self, text: str, **kwargs: Any) -> ScanResult:
527
+ """Scans text for prompt injection, secrets, PII, and security threats."""
528
+ return self.firewall.scan(text, **kwargs)
529
+
530
+ def scan_request(self, request: ScanRequest) -> ScanResult:
531
+ """Scans a structured ScanRequest."""
532
+ return self.firewall.scan_request(request)
533
+
534
+
535
+ __all__ = [
536
+
537
+ # Master Firewall Orchestrator & Configuration
538
+ "Firewall",
539
+ "FirewallConfig",
540
+ "ObservabilityConfig",
541
+ "IntegrationsConfig",
542
+ "RuntimeConfig",
543
+ "RuntimeLimitsConfig",
544
+ "DetectorConfig",
545
+ "PromptInjectionConfig",
546
+ "PIIConfig",
547
+ "SecretConfig",
548
+ "AuditConfig",
549
+ "TelemetryConfig",
550
+ # Models & Enums
551
+ "ThreatType",
552
+ "Severity",
553
+ "Action",
554
+ "DecisionAction",
555
+ "Finding",
556
+ "RiskScore",
557
+ "PolicyDecision",
558
+ "ScanRequest",
559
+ "ScanResult",
560
+ "FirewallResult",
561
+ "AuditEvent",
562
+ "MAX_SCAN_TEXT_LENGTH",
563
+ # Detector Architecture
564
+ "Detector",
565
+ "DetectorMetadata",
566
+ "DetectorEngine",
567
+ "FindingCollection",
568
+ "DetectorRegistry",
569
+ "default_detector_registry",
570
+ # Concrete Detectors
571
+ "PromptInjectionDetector",
572
+ "PIIDetector",
573
+ "SecretDetector",
574
+ "KeywordDetector",
575
+ # Risk Engine
576
+ "RiskEngine",
577
+ "RiskConfig",
578
+ # Policy Engine & Policy-as-Code
579
+ "Policy",
580
+ "PolicyEngine",
581
+ "PolicyConfig",
582
+ "PolicyRule",
583
+ "RuleCondition",
584
+ "LogicalOperator",
585
+ "PolicyValidationError",
586
+ "get_default_policy",
587
+ "RedactionConfig",
588
+ "SafeRedactor",
589
+ "default_redactor",
590
+ "ACTION_PRECEDENCE",
591
+ "redact_text_spans",
592
+ # Audit Logging
593
+ "AuditLogger",
594
+ "default_audit_logger",
595
+ # Observability & Security Telemetry
596
+ "TelemetryEvent",
597
+ "TelemetryEventType",
598
+ "TelemetrySink",
599
+ "NoOpTelemetry",
600
+ "InMemoryTelemetrySink",
601
+ "MetricsCollector",
602
+ "MetricSummary",
603
+ # Interfaces & Base
604
+ "BaseDetector",
605
+ "BaseRiskEngine",
606
+ "BasePolicyEngine",
607
+ # Exceptions
608
+ "LLMFirewallError",
609
+ "ConfigurationError",
610
+ "BlockedPromptError",
611
+ "BlockedOutputError",
612
+ # Agent & Tool Security (Phase 22)
613
+ "ToolCall",
614
+ "ToolResult",
615
+ "ToolPermission",
616
+ "ToolSecurityDecision",
617
+ "ToolDefinition",
618
+ "ToolRegistry",
619
+ "default_tool_registry",
620
+ "ToolSecurityEngine",
621
+ "ArgumentLimits",
622
+ "validate_argument_limits",
623
+ "validate_json_schema",
624
+ "validate_url_safety",
625
+ "validate_path_safety",
626
+ "inspect_command_safety",
627
+ "inspect_sql_safety",
628
+ # AI Security Evaluation & Red-Team Engine (Phase 23)
629
+ "SecurityEvaluationEngine",
630
+ "SecurityTestCase",
631
+ "SecurityTestResult",
632
+ "SecurityMetrics",
633
+ "SecurityDetectionCoverage",
634
+ "SecurityEvaluationReport",
635
+ "AttackCategory",
636
+ "TargetType",
637
+ "EvaluationTarget",
638
+ "FirewallTarget",
639
+ "get_builtin_security_test_cases",
640
+ "create_mutations",
641
+ "format_human_report",
642
+ "format_json_report",
643
+ "format_sarif_report",
644
+ "format_junit_report",
645
+ # Production Observability & Security Intelligence (Phase 24)
646
+ "SecurityEvent",
647
+ "SecurityEventType",
648
+ "EventSeverity",
649
+ "DecisionTrace",
650
+ "DecisionTraceStep",
651
+ "AnomalyEvent",
652
+ "hash_content",
653
+ "EventStore",
654
+ "InMemoryEventStore",
655
+ "JSONLEventStore",
656
+ "SQLiteEventStore",
657
+ "EventFilter",
658
+ "SecurityIntelligenceEngine",
659
+ "export_prometheus_metrics",
660
+ "export_events_json",
661
+ "export_events_jsonl",
662
+ "export_events_csv",
663
+ # Framework & Ecosystem Integrations (Phase 25)
664
+ "IntegrationsConfig",
665
+ "FirewallIntegration",
666
+ "IntegrationRegistry",
667
+ "SecurityViolation",
668
+ "protect",
669
+ # LLM & Agent Runtime Protection (Phase 26)
670
+ "RuntimeEngine",
671
+ "RuntimeSession",
672
+ "LoopGuard",
673
+ "RuntimeContext",
674
+ "RuntimeBoundary",
675
+ "TrustLevel",
676
+ "RuntimeEventType",
677
+ "RuntimeSecurityError",
678
+ "RuntimeLimitExceeded",
679
+ "RuntimeSecurityState",
680
+ "ContentItem",
681
+ "LLMMessage",
682
+ "LLMRequest",
683
+ "LLMResponse",
684
+ "RuntimeDecision",
685
+ "RuntimeHook",
686
+ "HookPipeline",
687
+ "LLMProviderAdapter",
688
+ "GenericProviderAdapter",
689
+ # Advanced RAG & Context Security (Phase 27)
690
+ "RAGConfig",
691
+ "IngestionConfig",
692
+ "ContextBudgetConfig",
693
+ "DocumentSecurityStatus",
694
+ "InstructionAuthority",
695
+ "SourceProvenance",
696
+ "ContextItem",
697
+ "DocumentIngestionResult",
698
+ "ContextSecurityDecision",
699
+ "SecurityScanCache",
700
+ "QuarantineStore",
701
+ "DocumentIngestionScanner",
702
+ "ContextOrchestrator",
703
+ "MemorySecurityGuard",
704
+ "CitationValidator",
705
+ # AI Supply-Chain & Model Security (Phase 28)
706
+ "SupplyChainConfig",
707
+ "ModelSecurityConfig",
708
+ "DependencySecurityConfig",
709
+ "ModelSourceType",
710
+ "ModelTrustLevel",
711
+ "ModelApprovalStatus",
712
+ "ModelFormat",
713
+ "IntegrityStatus",
714
+ "DependencyScope",
715
+ "DependencySourceType",
716
+ "ModelArtifact",
717
+ "ModelProvenance",
718
+ "IntegrityResult",
719
+ "ModelSecurityDecision",
720
+ "DependencyArtifact",
721
+ "VulnerabilityFinding",
722
+ "ConfigArtifact",
723
+ "PromptArtifact",
724
+ "PolicyArtifact",
725
+ "DeploymentMetadata",
726
+ "SnapshotDiff",
727
+ "SecuritySnapshot",
728
+ "ModelVerifier",
729
+ "ModelLoadingGuard",
730
+ "compute_streaming_hash",
731
+ "detect_model_format",
732
+ "is_unsafe_serialization",
733
+ "HASH_CHUNK_SIZE",
734
+ "ModelManifest",
735
+ "ModelSecurityRegistry",
736
+ "DependencyScanner",
737
+ "VulnerabilityProvider",
738
+ "OfflineVulnerabilityProvider",
739
+ "IntegrityManager",
740
+ "hash_configuration",
741
+ "hash_policy_artifact",
742
+ "hash_prompt_artifact",
743
+ "sanitize_config_dict",
744
+ # Agent Capability Security & Action Control (Phase 29)
745
+ "AgentCapabilitiesConfig",
746
+ "ActionClassification",
747
+ "SideEffectType",
748
+ "CapabilityRiskClass",
749
+ "ActionDecisionStatus",
750
+ "Capability",
751
+ "CapabilityGrant",
752
+ "DelegationGrant",
753
+ "ActionBudget",
754
+ "ActionRequest",
755
+ "ApprovalRequest",
756
+ "ActionDecision",
757
+ "ActionChain",
758
+ "ApprovalProvider",
759
+ "DenyAllApprovalProvider",
760
+ "CallbackApprovalProvider",
761
+ "MemoryApprovalProvider",
762
+ "BudgetManager",
763
+ "CapabilityEngine",
764
+ "DEFAULT_CAPABILITIES",
765
+ "DEFAULT_TOOL_CAPABILITY_MAP",
766
+ # Continuous AI Security Testing & Red-Team Engine (Phase 30)
767
+ "TestOrchestrator",
768
+ "SecurityTest",
769
+ "SecurityObservation",
770
+ "SecurityFinding",
771
+ "SecurityCoverage",
772
+ "TestStatus",
773
+ "ErrorCategory",
774
+ "AssertionType",
775
+ "DeclarativeAssertion",
776
+ "TargetAdapter",
777
+ "FirewallAdapter",
778
+ "MockAdapter",
779
+ "HTTPTargetAdapter",
780
+ "CallableAdapter",
781
+ "AgentAdapter",
782
+ "RAGAdapter",
783
+ "MockToolRegistry",
784
+ "SecurityTestSuite",
785
+ "BUILTIN_SUITES",
786
+ "SecurityTestGenerator",
787
+ "PromptInjectionGenerator",
788
+ "PIIGenerator",
789
+ "SecretGenerator",
790
+ "ToolSecurityGenerator",
791
+ "AgentCapabilityGenerator",
792
+ "RAGPoisoningGenerator",
793
+ "BoundedFuzzer",
794
+ "evaluate_assertion",
795
+ "evaluate_assertions",
796
+ "format_html_report",
797
+ "get_core_firewall_suite",
798
+ "get_prompt_injection_suite",
799
+ "get_pii_suite",
800
+ "get_secret_suite",
801
+ "get_tool_security_suite",
802
+ "get_agent_capability_suite",
803
+ "get_rag_security_suite",
804
+ "get_memory_security_suite",
805
+ "get_supply_chain_suite",
806
+ "get_configuration_integrity_suite",
807
+ "get_regression_suite",
808
+ "get_full_red_team_suite",
809
+ # AI Security Governance, Security Gates & Continuous Assurance (Phase 31)
810
+ "GovernanceDecision",
811
+ "ReasonCode",
812
+ "GateEvaluationResult",
813
+ "GovernanceResult",
814
+ "GateType",
815
+ "SecurityGate",
816
+ "FindingStatus",
817
+ "GovernanceFinding",
818
+ "SecurityWaiver",
819
+ "BaselineCategory",
820
+ "BaselineDiff",
821
+ "SecurityBaseline",
822
+ "EvidenceArtifactRecord",
823
+ "EvidenceManifest",
824
+ "SecurityReleaseManifest",
825
+ "SecurityEvidence",
826
+ "SecurityChangeClassification",
827
+ "ReleaseProfile",
828
+ "GovernancePolicy",
829
+ "GovernanceEngine",
830
+ "GovernanceOverride",
831
+ "SecurityGateFailure",
832
+ "GovernanceMetrics",
833
+ "format_governance_human",
834
+ "format_governance_json",
835
+ "format_governance_sarif",
836
+ # AI Security Knowledge Graph (Phase 32)
837
+ "KnowledgeGraph",
838
+ "GraphMetrics",
839
+ "GraphStore",
840
+ "InMemoryGraphStore",
841
+ "SQLiteGraphStore",
842
+ "Node",
843
+ "NodeType",
844
+ "Relationship",
845
+ "RelationshipType",
846
+ "GraphPath",
847
+ "GraphSnapshot",
848
+ "GraphDiff",
849
+ "SecurityDiff",
850
+ "SecurityImpactResult",
851
+ "BlastRadiusResult",
852
+ "ControlCoverageItem",
853
+ "ControlCoverageResult",
854
+ "ControlStatus",
855
+ "format_impact_human",
856
+ "format_blast_radius_human",
857
+ "format_coverage_human",
858
+ "format_graph_diff_human",
859
+ "format_node_show_human",
860
+ "format_path_human",
861
+ # Attack Graph & AI Threat Modeling (Phase 33)
862
+ "AttackGraph",
863
+ "AttackGraphMetrics",
864
+ "PathStatus",
865
+ "EvidenceType",
866
+ "MitigationStatus",
867
+ "ControlEffectiveness",
868
+ "EntryPointType",
869
+ "ConfidenceLevel",
870
+ "AttackEvidence",
871
+ "AttackTechnique",
872
+ "AttackNode",
873
+ "AttackStep",
874
+ "AttackPath",
875
+ "TrustBoundary",
876
+ "EntryPoint",
877
+ "ThreatModel",
878
+ "AttackGraphSnapshot",
879
+ "AttackGraphDiff",
880
+ "AttackTechniqueRegistry",
881
+ "default_technique_registry",
882
+ "AttackRule",
883
+ "AttackRuleRegistry",
884
+ "PreconditionEvaluator",
885
+ "STANDARD_RULES",
886
+ "format_attack_paths_human",
887
+ "format_threat_model_human",
888
+ "format_attack_paths_json",
889
+ "format_attack_graph_sarif",
890
+ # AI Asset Inventory & Discovery (Phase 34)
891
+ "Asset",
892
+ "AssetType",
893
+ "AssetStatus",
894
+ "AssetSource",
895
+ "DiscoveryConfidence",
896
+ "DiscoveryStatus",
897
+ "AssetProvenance",
898
+ "AssetConflict",
899
+ "DiscoveryResult",
900
+ "InventorySnapshot",
901
+ "InventoryDiff",
902
+ "AssetExposure",
903
+ "AssetInventory",
904
+ "DiscoveryEngine",
905
+ "InventoryMetrics",
906
+ "normalize_asset_id",
907
+ "sanitize_metadata_secrets",
908
+ "DiscoveryProvider",
909
+ "ConfigDiscoveryProvider",
910
+ "EnvironmentDiscoveryProvider",
911
+ "DependencyDiscoveryProvider",
912
+ "CodeDiscoveryProvider",
913
+ "ImportDiscoveryProvider",
914
+ "RuntimeDiscoveryProvider",
915
+ "ManualDiscoveryProvider",
916
+ "format_inventory_list_human",
917
+ "format_asset_show_human",
918
+ "format_discovery_result_human",
919
+ "format_inventory_diff_human",
920
+ "format_inventory_json",
921
+ "format_discovery_result_json",
922
+ # AI Security Posture Management (Phase 35)
923
+ "PostureEngine",
924
+ "PostureMetrics",
925
+ "PostureState",
926
+ "PostureDimension",
927
+ "ControlPresence",
928
+ "SecurityGapStatus",
929
+ "TestFreshness",
930
+ "ControlPostureRecord",
931
+ "TestCoverageRecord",
932
+ "AttackSurfaceRecord",
933
+ "SecurityGap",
934
+ "SecurityPosture",
935
+ "PostureSnapshot",
936
+ "PostureDiff",
937
+ "PostureRule",
938
+ "PostureRuleContext",
939
+ "PostureRuleRegistry",
940
+ "format_posture_human",
941
+ "format_posture_summary_human",
942
+ "format_posture_diff_human",
943
+ "format_posture_json",
944
+ "format_posture_sarif",
945
+ "sanitize_posture_metadata",
946
+ # AI Security Compliance & Control Mapping (Phase 36)
947
+ "ControlState",
948
+ "ApplicabilityStatus",
949
+ "ComplianceEvidenceType",
950
+ "EvidenceValidity",
951
+ "RemediationStatus",
952
+ "ExceptionStatus",
953
+ "MappingType",
954
+ "ComplianceControl",
955
+ "ComplianceFramework",
956
+ "ComplianceEvidence",
957
+ "ComplianceException",
958
+ "ComplianceGap",
959
+ "ControlAssessment",
960
+ "ControlMapping",
961
+ "CrossFrameworkMapping",
962
+ "ComplianceSnapshot",
963
+ "ComplianceDiff",
964
+ "sanitize_compliance_metadata",
965
+ "ControlCatalog",
966
+ "AI_SECURITY_BASELINE_CONTROLS",
967
+ "ComplianceRuleContext",
968
+ "ComplianceRule",
969
+ "ComplianceRuleRegistry",
970
+ "STANDARD_COMPLIANCE_RULES",
971
+ "ComplianceEngine",
972
+ "ComplianceMetrics",
973
+ "format_compliance_human",
974
+ "format_control_detail_human",
975
+ "format_gaps_human",
976
+ "format_evidence_human",
977
+ "format_compliance_json",
978
+ "format_compliance_yaml",
979
+ # AI Security Risk & Prioritization (Phase 37)
980
+ "RiskPrioritizationEngine",
981
+ "RiskAssessment",
982
+ "RiskLevel",
983
+ "RiskUncertainty",
984
+ "RiskTreatment",
985
+ "RiskFactor",
986
+ "RiskFactorType",
987
+ "RiskSnapshot",
988
+ "RiskDiff",
989
+ "RiskHistoryEntry",
990
+ "format_risk_human",
991
+ "format_risk_detail_human",
992
+ "format_risk_diff_human",
993
+ "format_risk_json",
994
+ "format_risk_yaml",
995
+ # AI Security Incident Response & Investigation (Phase 38)
996
+ "SecurityEvent",
997
+ "SecurityEventType",
998
+ "SecurityIncident",
999
+ "IncidentSeverity",
1000
+ "IncidentStatus",
1001
+ "IncidentAction",
1002
+ "IncidentActionRecord",
1003
+ "EvidenceItem",
1004
+ "TimelineEntry",
1005
+ "compute_evidence_hash",
1006
+ "IncidentManager",
1007
+ "IncidentError",
1008
+ "IncidentDetectionRule",
1009
+ "IncidentCandidate",
1010
+ "RepeatedUnauthorizedToolCallsRule",
1011
+ "PromptInjectionFollowedByPrivilegedToolRule",
1012
+ "SecretExposureRule",
1013
+ "PolicyBypassRule",
1014
+ "AbnormalAgentBehaviorRule",
1015
+ "get_default_incident_rules",
1016
+ "format_incidents_table_human",
1017
+ "format_incident_detail_human",
1018
+ "format_incident_timeline_human",
1019
+ "generate_post_incident_report",
1020
+ # AI Security Runtime Protection & Policy Enforcement (Phase 39)
1021
+ "RuntimeProtectionEngine",
1022
+ "PolicyDecision",
1023
+ "PolicyMode",
1024
+ "FailBehavior",
1025
+ "RuntimeRequest",
1026
+ "RuntimeDecision",
1027
+ "ProtectionAuditEntry",
1028
+ "ProtectionPolicy",
1029
+ "ProtectionRule",
1030
+ "ProtectionCondition",
1031
+ "RateLimitRule",
1032
+ "RateLimiter",
1033
+ "get_default_production_policy",
1034
+ "protect",
1035
+ "protect_tool",
1036
+ "LLMFirewallMiddleware",
1037
+ "SecurityBlockError",
1038
+ # Production Hardening & v1.0 Public API (Phase 40)
1039
+ "Scanner",
1040
+ ]
1041
+