blindsight-security 1.0.0__tar.gz
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.
- blindsight_security-1.0.0/LICENSE +202 -0
- blindsight_security-1.0.0/MANIFEST.in +3 -0
- blindsight_security-1.0.0/NOTICE +7 -0
- blindsight_security-1.0.0/PKG-INFO +327 -0
- blindsight_security-1.0.0/README.md +303 -0
- blindsight_security-1.0.0/blindsight_security/__init__.py +86 -0
- blindsight_security-1.0.0/blindsight_security/client.py +489 -0
- blindsight_security-1.0.0/blindsight_security/errors.py +71 -0
- blindsight_security-1.0.0/blindsight_security/models.py +570 -0
- blindsight_security-1.0.0/blindsight_security/proxy.py +163 -0
- blindsight_security-1.0.0/blindsight_security/py.typed +0 -0
- blindsight_security-1.0.0/blindsight_security.egg-info/PKG-INFO +327 -0
- blindsight_security-1.0.0/blindsight_security.egg-info/SOURCES.txt +16 -0
- blindsight_security-1.0.0/blindsight_security.egg-info/dependency_links.txt +1 -0
- blindsight_security-1.0.0/blindsight_security.egg-info/requires.txt +12 -0
- blindsight_security-1.0.0/blindsight_security.egg-info/top_level.txt +1 -0
- blindsight_security-1.0.0/pyproject.toml +35 -0
- blindsight_security-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Blindsight Runtime Security SDK
|
|
2
|
+
Copyright 2026 Blindsight Technologies AG
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
This license covers this client library only. The Blindsight service it
|
|
7
|
+
connects to is provided under Blindsight's own terms of service.
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: blindsight-security
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for Blindsight Runtime Security: scan prompts, responses, files and tool-calls, or route your LLM traffic through the guardrail reverse proxy.
|
|
5
|
+
Author: Blindsight Technologies AG
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://blindsight.io
|
|
8
|
+
Project-URL: Documentation, https://docs.blindsight.io
|
|
9
|
+
Keywords: blindsight,runtime-security,llm,guardrails,dlp,prompt-injection,pii
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: NOTICE
|
|
14
|
+
Requires-Dist: httpx>=0.27
|
|
15
|
+
Provides-Extra: openai
|
|
16
|
+
Requires-Dist: openai>=1.0; extra == "openai"
|
|
17
|
+
Provides-Extra: anthropic
|
|
18
|
+
Requires-Dist: anthropic>=0.25; extra == "anthropic"
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
22
|
+
Requires-Dist: mypy>=1.8; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# Blindsight Runtime Security: Python SDK
|
|
26
|
+
|
|
27
|
+
The official Python client for [Blindsight Runtime Security](https://blindsight.io).
|
|
28
|
+
Inspect prompts, responses, files, and agent tool-calls for prompt injection and
|
|
29
|
+
sensitive data, or route your existing LLM client through the guardrail proxy.
|
|
30
|
+
|
|
31
|
+
## Requirements
|
|
32
|
+
|
|
33
|
+
- Python 3.9 or later
|
|
34
|
+
- A single runtime dependency (`httpx`)
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install blindsight-security
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Optional extras add convenience factories that return a preconfigured vendor client:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install "blindsight-security[openai]" # rs.proxy.openai_client()
|
|
46
|
+
pip install "blindsight-security[anthropic]" # rs.proxy.anthropic_client()
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
Scan the prompt before it reaches the model, and the response before it reaches
|
|
52
|
+
the user:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from openai import OpenAI
|
|
56
|
+
from blindsight_security import RuntimeSecurity
|
|
57
|
+
|
|
58
|
+
rs = RuntimeSecurity(
|
|
59
|
+
base_url="https://platform.blindsight.io",
|
|
60
|
+
api_key="ak_…",
|
|
61
|
+
app_id="<App id>", # optional
|
|
62
|
+
)
|
|
63
|
+
openai = OpenAI()
|
|
64
|
+
|
|
65
|
+
verdict = rs.scan_input(user_text, provider="openai", model="gpt-4o")
|
|
66
|
+
if verdict.blocked:
|
|
67
|
+
raise PermissionError(verdict.blocked_reason)
|
|
68
|
+
safe_prompt = verdict.safe_text # redacted when the prompt carries PII
|
|
69
|
+
|
|
70
|
+
completion = openai.chat.completions.create(
|
|
71
|
+
model="gpt-4o",
|
|
72
|
+
messages=[{"role": "user", "content": safe_prompt}],
|
|
73
|
+
)
|
|
74
|
+
answer = completion.choices[0].message.content
|
|
75
|
+
|
|
76
|
+
result = rs.scan_output(answer, prompt=safe_prompt)
|
|
77
|
+
final = result.safe_text # empty when blocked
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Scanning
|
|
81
|
+
|
|
82
|
+
### Content the user did not write
|
|
83
|
+
|
|
84
|
+
If the prompt is assembled from more than the user's own words, say so. Pass the
|
|
85
|
+
retrieved documents, tool results, fetched pages or email bodies as untrusted
|
|
86
|
+
spans and the firewall judges them as data: inside a declared span an
|
|
87
|
+
instruction aimed at the assistant is a finding however ordinary it sounds,
|
|
88
|
+
because the user never asked for it.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from blindsight_security import UntrustedSpan
|
|
92
|
+
|
|
93
|
+
verdict = rs.scan_input(
|
|
94
|
+
prompt,
|
|
95
|
+
untrusted=[
|
|
96
|
+
UntrustedSpan.retrieved(chunk, label="kb-8842"),
|
|
97
|
+
UntrustedSpan.tool_result(tool_output, label="calendar"),
|
|
98
|
+
],
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
for i in verdict.flagged_span_indices:
|
|
102
|
+
logger.warning("span %s was steering the model; dropping it", i)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Why it matters: the hardest indirect injections are not menacing. "Summarize
|
|
106
|
+
the main findings of the 2020 climate report" is the most ordinary request there
|
|
107
|
+
is from a user, and an attack from inside a retrieved document. Nothing in the
|
|
108
|
+
text separates the two, only where it came from.
|
|
109
|
+
|
|
110
|
+
`tool_result` and `web` are strict by default, because a tool returning prose
|
|
111
|
+
that tells the assistant what to do next is compromised or misdesigned. The
|
|
112
|
+
others are balanced, because retrieved prose legitimately contains imperatives
|
|
113
|
+
and questions. Override per span with `strictness="strict"` or `"balanced"`.
|
|
114
|
+
A bare string is accepted and defaults to `retrieval`. At most 32 spans, and
|
|
115
|
+
only `scan_input` takes them.
|
|
116
|
+
|
|
117
|
+
Findings come back per span on `verdict.untrusted`, so an offending document can
|
|
118
|
+
be dropped or re-fetched without failing the whole request. `verdict.untrusted`
|
|
119
|
+
is `None` when no spans were declared, which is not the same as declared and
|
|
120
|
+
clean.
|
|
121
|
+
|
|
122
|
+
### Conversations
|
|
123
|
+
|
|
124
|
+
An App can act on one kind of personal data only when another has been part of
|
|
125
|
+
the same conversation, for example mask a person's name only once a national
|
|
126
|
+
ID or an account number has appeared, in an earlier turn or a later one. Name
|
|
127
|
+
the conversation with `session_id` and, optionally, number the turns:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
result = rs.scan_input(prompt, session_id=conversation_id, turn=3)
|
|
131
|
+
|
|
132
|
+
conv = result.conversation # None when the App has no conversation conditions
|
|
133
|
+
if conv and conv["exposed_earlier"]:
|
|
134
|
+
# An earlier turn sent a value out before this turn's trigger arrived.
|
|
135
|
+
for item in conv["exposed_earlier"]:
|
|
136
|
+
purge_turn(item["turn"])
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`conv["state"]` is `new`, `continued`, `unknown` (a later turn of a
|
|
140
|
+
conversation the platform no longer remembers), `saturated` or `unavailable`.
|
|
141
|
+
In the last three the App's setting decides: by default every target is masked
|
|
142
|
+
as if its trigger had been seen. A retried call with the same `turn` is not
|
|
143
|
+
counted twice. The platform remembers keyed hashes and data-type labels, never
|
|
144
|
+
the values or the conversation id.
|
|
145
|
+
|
|
146
|
+
### Pseudonymize and restore
|
|
147
|
+
|
|
148
|
+
On an App set to pseudonymize, personal data comes back as placeholders such
|
|
149
|
+
as `<PERSON_1>` and `<EMAIL_ADDRESS_1>`, with a mapping to the real values in
|
|
150
|
+
`result.pseudonyms`. Send the placeholders to your model and put the values
|
|
151
|
+
back in its reply:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
inp = rs.scan_input(user_text, session_id=conversation_id)
|
|
155
|
+
reply = call_your_model(inp.safe_text) # the model sees placeholders only
|
|
156
|
+
out = rs.scan_output(reply, prompt=inp.safe_text, session_id=conversation_id)
|
|
157
|
+
if out.blocked:
|
|
158
|
+
return "Sorry, I can't help with that."
|
|
159
|
+
safe = out.safe_text
|
|
160
|
+
for token in (out.pseudonyms or {}): # data the model wrote on its own
|
|
161
|
+
safe = safe.replace(token, "[hidden]")
|
|
162
|
+
final = inp.restore(safe) # the user's own values go back in
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Each call numbers its placeholders from 1, so `<PERSON_1>` in two calls can
|
|
166
|
+
be two people. If your model is given the earlier turns too, renumber each
|
|
167
|
+
turn into one numbering for the conversation before you send it, and restore
|
|
168
|
+
with that conversation's mapping.
|
|
169
|
+
|
|
170
|
+
Send the same `session_id` for a whole conversation and the text the model
|
|
171
|
+
saw as `prompt`. Hiding the output's own placeholders before restoring means a
|
|
172
|
+
value the model wrote itself is never replaced by one of your user's values.
|
|
173
|
+
A placeholder is `<KIND_n>`, sometimes with a short tag before the number
|
|
174
|
+
(`<PERSON_T3_1>`); `restore` handles both. The mapping is in the response
|
|
175
|
+
only. Keep it server-side and never log it.
|
|
176
|
+
|
|
177
|
+
### Files
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
with open("resume.pdf", "rb") as f:
|
|
181
|
+
result = rs.scan_file(f.read(), filename="resume.pdf", media_type="application/pdf")
|
|
182
|
+
|
|
183
|
+
if result.was_redacted:
|
|
184
|
+
open("resume.clean.pdf", "wb").write(result.file_bytes)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Agent tool-calls
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
gate = rs.scan_tool_call("delete_file", {"path": requested_path})
|
|
191
|
+
gate.raise_for_block() # raises ContentBlocked on a block verdict
|
|
192
|
+
delete_file(**gate.safe_arguments)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### MCP tool verification
|
|
196
|
+
|
|
197
|
+
Verify an MCP tool's integrity before you trust it. This scans the description
|
|
198
|
+
for poisoning, pins its description/schema on first use to catch a later
|
|
199
|
+
**rug-pull** or **schema poisoning**, flags cross-server **shadowing**, and can
|
|
200
|
+
scan a tool's returned output for injected content. The verdict honours the
|
|
201
|
+
App's configured enforcement mode.
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
check = rs.verify_tool(
|
|
205
|
+
server="example-mcp",
|
|
206
|
+
name="send_email",
|
|
207
|
+
description=tool.description,
|
|
208
|
+
schema=tool.input_schema, # optional; enables schema-poisoning detection
|
|
209
|
+
)
|
|
210
|
+
check.raise_for_block() # blocks a rug-pulled / shadowed tool
|
|
211
|
+
if check.rug_pull or check.shadowed:
|
|
212
|
+
... # or handle it yourself
|
|
213
|
+
|
|
214
|
+
# Scan a result the tool returned (indirect prompt injection, ASCII smuggling):
|
|
215
|
+
rs.verify_tool("example-mcp", "search", tool_result=result_text).raise_for_block()
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`MCPVerifyResult` exposes `verdict`, `reasons`, `registry`, `shadowing`,
|
|
219
|
+
`description_scan`, `result_scan`, `max_severity`, `blocked_reason`, the
|
|
220
|
+
convenience flags `allowed` / `flagged` / `blocked` / `rug_pull` / `shadowed`,
|
|
221
|
+
and `raise_for_block()`.
|
|
222
|
+
|
|
223
|
+
### Batch
|
|
224
|
+
|
|
225
|
+
Up to 32 texts in a single round-trip:
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
results = rs.scan_batch([
|
|
229
|
+
{"text": doc_a, "direction": "input"},
|
|
230
|
+
{"text": doc_b, "direction": "input"},
|
|
231
|
+
])
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Result fields
|
|
235
|
+
|
|
236
|
+
Every result exposes `uuid`, `verdict`, `injection`, `pii`, `redacted_text`,
|
|
237
|
+
`blocked_reason`, `latency_ms`, and `text_length`, along with the convenience
|
|
238
|
+
accessors `allowed` / `flagged` / `was_redacted` / `blocked`, `safe_text`,
|
|
239
|
+
`injection_score`, `pii_categories`, `raise_for_block()`, and `raw` (the full
|
|
240
|
+
JSON response).
|
|
241
|
+
|
|
242
|
+
## Reverse proxy
|
|
243
|
+
|
|
244
|
+
Route an existing vendor client through the guardrail without writing explicit
|
|
245
|
+
scan calls:
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from openai import OpenAI
|
|
249
|
+
client = OpenAI(api_key=OPENAI_KEY, **rs.proxy.openai())
|
|
250
|
+
|
|
251
|
+
from anthropic import Anthropic
|
|
252
|
+
anthropic = Anthropic(api_key=ANTHROPIC_KEY, **rs.proxy.anthropic())
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Additional providers are available via `rs.proxy.gemini()`, `rs.proxy.vertex()`,
|
|
256
|
+
`rs.proxy.bedrock()`, and `rs.proxy.openai_compatible(provider="groq")`.
|
|
257
|
+
|
|
258
|
+
### LangChain and LlamaIndex
|
|
259
|
+
|
|
260
|
+
Both frameworks wrap the OpenAI client, so the proxy configuration applies
|
|
261
|
+
directly:
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
from langchain_openai import ChatOpenAI
|
|
265
|
+
llm = ChatOpenAI(model="gpt-4o", api_key=OPENAI_KEY, **rs.proxy.openai())
|
|
266
|
+
|
|
267
|
+
from llama_index.llms.openai import OpenAI as LlamaOpenAI
|
|
268
|
+
cfg = rs.proxy.openai()
|
|
269
|
+
llm = LlamaOpenAI(
|
|
270
|
+
model="gpt-4o",
|
|
271
|
+
api_key=OPENAI_KEY,
|
|
272
|
+
api_base=cfg["base_url"],
|
|
273
|
+
default_headers=cfg["default_headers"],
|
|
274
|
+
)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Error handling
|
|
278
|
+
|
|
279
|
+
All exceptions derive from `BlindsightError`:
|
|
280
|
+
|
|
281
|
+
- `BlindsightAPIError`: a non-2xx answer, with `.status_code`, `.code` (for
|
|
282
|
+
example `APP_NOT_ALLOWED`) and `.retry_after` when the answer gave one
|
|
283
|
+
- `BlindsightAuthError` (401 / 403): a wrong, revoked or expired key, or a
|
|
284
|
+
key not allowed for this App
|
|
285
|
+
- `BlindsightQuotaError` (402 / 429). A 429 with code
|
|
286
|
+
`DAILY_ALLOWANCE_SOFT_LIMIT` is temporary: requests are paced, so wait
|
|
287
|
+
`.retry_after` seconds and send the same call again
|
|
288
|
+
- `BlindsightConnectionError`: no answer (network failure or timeout)
|
|
289
|
+
- `ContentBlocked`: raised by `raise_for_block()` on a block verdict
|
|
290
|
+
|
|
291
|
+
Error messages never contain your key or the text you sent.
|
|
292
|
+
|
|
293
|
+
### When Blindsight cannot answer
|
|
294
|
+
|
|
295
|
+
The client never answers for you. Every failure is an exception, so nothing
|
|
296
|
+
reaches your model unscanned unless your own code decides to send it. Choose
|
|
297
|
+
what your application does in that case: refusing to answer is the safe
|
|
298
|
+
default; answering without protection sends personal data to your model.
|
|
299
|
+
|
|
300
|
+
- `timeout` (default 10 seconds) bounds each request.
|
|
301
|
+
- `max_retries` (default 2) retries a 429 or a 503, and a connection
|
|
302
|
+
that never reached the server, with a growing pause and `Retry-After`
|
|
303
|
+
honoured. A timeout is never retried, because the scan may already have run.
|
|
304
|
+
- `max_retry_wait` (default 30 seconds) caps the time all retries of one call
|
|
305
|
+
may wait. A longer `Retry-After` is not waited for: the error is raised at
|
|
306
|
+
once, with `.retry_after` set.
|
|
307
|
+
|
|
308
|
+
```python
|
|
309
|
+
rs = RuntimeSecurity(base_url=..., api_key=..., timeout=5, max_retries=2, max_retry_wait=10)
|
|
310
|
+
try:
|
|
311
|
+
verdict = rs.scan_input(user_text)
|
|
312
|
+
except BlindsightConnectionError:
|
|
313
|
+
return "The assistant is unavailable for a moment." # fail closed
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Development
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
pip install -e ".[dev]"
|
|
320
|
+
pytest
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## License
|
|
324
|
+
|
|
325
|
+
Apache-2.0, Copyright 2026 Blindsight Technologies AG: see `LICENSE` and
|
|
326
|
+
`NOTICE`. The license covers this client library; the Blindsight service it connects to stays under Blindsight's own
|
|
327
|
+
terms of service.
|