Python API Reference
RAGuardScanner
raguard.scanner.RAGuardScanner
Main scanning engine that orchestrates detectors against RAG targets.
Source code in src/raguard/scanner.py
22 23 24 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 | |
add_detector(detector_cls)
Add a detector to the scanner.
Source code in src/raguard/scanner.py
40 41 42 | |
clear_detectors()
Clear all detectors.
Source code in src/raguard/scanner.py
44 45 46 | |
scan(target)
async
Execute a full security scan against a RAG target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
RAGTargetConfig
|
Configuration for the RAG system to test. |
required |
Returns:
| Type | Description |
|---|---|
RAGScanReport
|
Complete scan report with all findings. |
Source code in src/raguard/scanner.py
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 | |
scan_url(url, target_type=TargetType.GENERIC, **kwargs)
async
Convenience method to scan by URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Target URL. |
required |
target_type
|
TargetType
|
Type of RAG system. |
GENERIC
|
**kwargs
|
str
|
Additional target config options. |
{}
|
Returns:
| Type | Description |
|---|---|
RAGScanReport
|
Scan report. |
Source code in src/raguard/scanner.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
Models
raguard.models.RAGTargetConfig
Bases: BaseModel
Configuration for a RAG system target.
Source code in src/raguard/models.py
73 74 75 76 77 78 79 80 81 82 83 | |
raguard.models.RAGFinding
Bases: BaseModel
A single security finding from a RAG scan.
Source code in src/raguard/models.py
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 | |
raguard.models.RAGScanReport
Bases: BaseModel
Complete scan report.
Source code in src/raguard/models.py
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 | |
compute_risk()
Compute aggregate risk score from findings.
Source code in src/raguard/models.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
raguard.models.Severity
Bases: StrEnum
Finding severity levels.
Source code in src/raguard/models.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
raguard.models.Confidence
Bases: StrEnum
Detection confidence levels.
Source code in src/raguard/models.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
raguard.models.RAGAttackType
Bases: StrEnum
Types of RAG-specific attacks.
Source code in src/raguard/models.py
12 13 14 15 16 17 18 19 20 21 | |
raguard.models.TargetType
Bases: StrEnum
Supported RAG target types.
Source code in src/raguard/models.py
64 65 66 67 68 69 70 | |
Detectors
raguard.detectors.base.BaseDetector
Bases: ABC
Abstract base for all RAG security detectors.
Source code in src/raguard/detectors/base.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
detect(target)
abstractmethod
async
Run detection against a RAG target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
RAGTargetConfig
|
Configuration for the RAG system to test. |
required |
Returns:
| Type | Description |
|---|---|
list[RAGFinding]
|
List of security findings. |
Source code in src/raguard/detectors/base.py
16 17 18 19 20 21 22 23 24 25 26 | |
raguard.detectors.registry.get_detector(name)
Get a registered detector by name.
Source code in src/raguard/detectors/registry.py
25 26 27 | |
raguard.detectors.registry.get_all_detectors()
Get all registered detectors.
Source code in src/raguard/detectors/registry.py
30 31 32 | |
Reporters
raguard.reporters.json.JSONReporter
JSON reporter for RAGuard scan results.
Source code in src/raguard/reporters/json.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 | |
render(report)
Render scan report as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
RAGScanReport
|
The scan report to render. |
required |
Returns:
| Type | Description |
|---|---|
str
|
JSON string. |
Source code in src/raguard/reporters/json.py
13 14 15 16 17 18 19 20 21 22 23 24 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 | |
raguard.reporters.html.HTMLReporter
HTML reporter using Jinja2 templates.
Source code in src/raguard/reporters/html.py
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 | |
render(report)
Render scan report as HTML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
RAGScanReport
|
The scan report to render. |
required |
Returns:
| Type | Description |
|---|---|
str
|
HTML string. |
Source code in src/raguard/reporters/html.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
render_to_file(report, output_path)
Render and save report to HTML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
RAGScanReport
|
The scan report. |
required |
output_path
|
str
|
Path to save the HTML file. |
required |
Source code in src/raguard/reporters/html.py
112 113 114 115 116 117 118 119 120 | |
raguard.reporters.sarif.SARIFReporter
SARIF v2.1.0 reporter for GitHub Code Scanning.
Source code in src/raguard/reporters/sarif.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 | |
render(report)
Render scan report as SARIF JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
RAGScanReport
|
The scan report to render. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SARIF JSON string. |
Source code in src/raguard/reporters/sarif.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
raguard.reporters.console.ConsoleReporter
Rich console reporter for RAGuard scan results.
Source code in src/raguard/reporters/console.py
12 13 14 15 16 17 18 19 20 21 22 23 24 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 | |
render(report)
Render scan report to Rich console output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
RAGScanReport
|
The scan report to render. |
required |
Returns:
| Type | Description |
|---|---|
str
|
String representation (also prints to console). |
Source code in src/raguard/reporters/console.py
15 16 17 18 19 20 21 22 23 24 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 | |
Utilities
raguard.utils.http.RAGuardHTTPClient
Async HTTP client with retries and timeouts for RAG scanning.
Security features: - SSRF protection via URL validation - Redirect following disabled by default - Configurable timeouts and retries
Source code in src/raguard/utils/http.py
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 | |
close()
async
Close the HTTP client.
Source code in src/raguard/utils/http.py
104 105 106 107 108 | |
get(url, **kwargs)
async
Perform GET request with retries and SSRF validation.
Source code in src/raguard/utils/http.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
get_client()
async
Get or create the HTTP client.
Source code in src/raguard/utils/http.py
94 95 96 97 98 99 100 101 102 | |
post(url, json=None, **kwargs)
async
Perform POST request with retries and SSRF validation.
Source code in src/raguard/utils/http.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
raguard.utils.embeddings.cosine_similarity(a, b)
Compute cosine similarity between two vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
First vector. |
required |
b
|
ndarray
|
Second vector. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Cosine similarity score between -1 and 1. |
Source code in src/raguard/utils/embeddings.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |