You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guardrails/images.md
+14-40Lines changed: 14 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,67 +1,41 @@
1
-
# Images (WIP)
1
+
# Images
2
2
3
3
<divclass='subtitle'>
4
-
Guardrail the visual perception of your agentic system.
4
+
Secure images given to, or produced by, your agentic system.
5
5
</div>
6
6
7
7
At the core of computer vision agents is the ability to perceive their environment through images, typically by taking screenshots to assess the current state. This visual perception allows agents to understand interfaces, identify interactive elements, and make decisions based on what they "see."
8
8
9
-
For security and privacy reasons, it is important to ensure that all visual information an agent processes is validated and well-scoped, to prevent exposure of sensitive information or inappropriate content.
10
-
11
-
Guardrails provide you a powerful way to enforce visual security policies, and to limit the agent's perception to only the visual information that is necessary and appropriate for the task at hand.
9
+
Additionally, some systems may allow users to submit images, posing additional risks.
12
10
13
11
<divclass='risks'/>
14
12
> **Image Risks**<br/>
15
-
> Since images are an agent's window to perceive the world, they can expose sensitive or inappropriate content. For example, an insecure vision agent could:
13
+
> Images may be produced by, or provided to, an agentic system, presenting potential security risks. For example, an insecure agent could:
16
14
17
-
> * Capture personally identifiable information (PII) like names or addresses
15
+
> * Capture **personally identifiable information (PII)** like names or addresses.
18
16
>
19
-
> * View credentials such as passwords, API keys, or access tokens
17
+
> * View credentials such as **passwords, API keys, or access tokens**.
20
18
>
21
-
> * Capture copyrighted material that shouldn't be processed or shared
22
-
23
-
## Checking Image Content
24
-
25
-
**Example**: Checking for PII in images
26
-
27
-
```python
28
-
from invariant.parsers import ocr
19
+
> * Get **prompt injected** from text in an image.
29
20
30
-
raise"PII in image text"if:
31
-
(img: Image)
32
-
image_text := ocr(img)
33
-
any(pii(image_text))
34
-
```
35
-
36
-
**Example**: Check copyrighted material
37
21
38
-
39
-
// Maybe something that uses the information in the image
40
-
// So combine with like toolcalls?
41
-
```python
42
-
from...
43
-
44
-
raise"Copyrighted text in image"if:
45
-
(msg: Assistant)
46
-
images := image(msg) # Extract all images in a single message
47
-
copyright(ocr(images))
48
-
```
22
+
Guardrails provide you a powerful way to enforce visual security policies, and to limit the agent's perception to only the visual information that is necessary and appropriate for the task at hand.
49
23
50
24
51
25
## ocr <spanclass="parser-badge"/>
52
26
```python
53
27
defocr(
54
-
data: Union[str, List[str]],
28
+
data: str, List[str],
55
29
config: Optional[dict]
56
30
) -> List[str]
57
31
```
58
-
Parser to extract text from images.
32
+
Given an image asinput, this parser extracts and returns the text in the image using [Tesseract](https://github.com/tesseract-ocr/tesseract).
|`data`|`Union[str, List[str]]`| A single base64 encoded image or a list of base64 encoded images. |
38
+
|`data`|`str, List[str]`| A single base64 encoded image or a list of base64 encoded images. |
65
39
66
40
**Returns**
67
41
@@ -70,7 +44,7 @@ Parser to extract text from images.
70
44
|`List[str]`| A list of extracted pieces of text from`data`. |
71
45
72
46
### Analyzing Text in Images
73
-
The `ocr` function is a <span class="parser-badge" size-mod="small"></span> so it returns the data found from parsing its content,in this case extracting text froman image. The extracted text can then be used for further detection, for example detecting a prompt injection in an image, like the example below.
47
+
The `ocr` function is a <span class="parser-badge" size-mod="small"></span> so it returns the data found from parsing its content;in this case any text present inan image will be extracted. The extracted text can then be used for further detection, for example detecting a prompt injection in an image, like the example below.
Given some `Content`, this <span class="builtin-badge" size-mod="small"></span> extracts all images. This is useful when messages may contain mixed content.
@@ -98,7 +72,7 @@ Given some `Content`, this <span class="builtin-badge" size-mod="small"></span>
0 commit comments