pangea-sdk 5.4.0b3__tar.gz → 5.5.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.
Files changed (62) hide show
  1. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/PKG-INFO +9 -9
  2. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/README.md +2 -2
  3. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/__init__.py +1 -1
  4. pangea_sdk-5.5.0/pangea/asyncio/services/ai_guard.py +221 -0
  5. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/prompt_guard.py +16 -8
  6. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/share.py +2 -2
  7. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/config.py +6 -4
  8. pangea_sdk-5.5.0/pangea/services/ai_guard.py +323 -0
  9. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/prompt_guard.py +19 -11
  10. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/share/share.py +1 -1
  11. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pyproject.toml +10 -10
  12. pangea_sdk-5.4.0b3/pangea/asyncio/services/ai_guard.py +0 -75
  13. pangea_sdk-5.4.0b3/pangea/services/ai_guard.py +0 -128
  14. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/__init__.py +0 -0
  15. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/file_uploader.py +0 -0
  16. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/request.py +0 -0
  17. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/__init__.py +0 -0
  18. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/audit.py +0 -0
  19. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/authn.py +0 -0
  20. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/authz.py +0 -0
  21. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/base.py +0 -0
  22. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/embargo.py +0 -0
  23. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/file_scan.py +0 -0
  24. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/intel.py +0 -0
  25. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/redact.py +0 -0
  26. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/sanitize.py +0 -0
  27. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/asyncio/services/vault.py +0 -0
  28. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/audit_logger.py +0 -0
  29. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/crypto/rsa.py +0 -0
  30. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/deep_verify.py +0 -0
  31. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/deprecated.py +0 -0
  32. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/dump_audit.py +0 -0
  33. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/exceptions.py +0 -0
  34. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/file_uploader.py +0 -0
  35. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/py.typed +0 -0
  36. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/request.py +0 -0
  37. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/response.py +0 -0
  38. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/__init__.py +0 -0
  39. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/audit/audit.py +0 -0
  40. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/audit/exceptions.py +0 -0
  41. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/audit/models.py +0 -0
  42. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/audit/signing.py +0 -0
  43. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/audit/util.py +0 -0
  44. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/authn/authn.py +0 -0
  45. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/authn/models.py +0 -0
  46. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/authz.py +0 -0
  47. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/base.py +0 -0
  48. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/embargo.py +0 -0
  49. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/file_scan.py +0 -0
  50. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/intel.py +0 -0
  51. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/redact.py +0 -0
  52. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/sanitize.py +0 -0
  53. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/share/file_format.py +0 -0
  54. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/vault/models/asymmetric.py +0 -0
  55. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/vault/models/common.py +0 -0
  56. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/vault/models/keys.py +0 -0
  57. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/vault/models/secret.py +0 -0
  58. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/vault/models/symmetric.py +0 -0
  59. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/services/vault/vault.py +0 -0
  60. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/tools.py +0 -0
  61. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/utils.py +0 -0
  62. {pangea_sdk-5.4.0b3 → pangea_sdk-5.5.0}/pangea/verify_audit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pangea-sdk
3
- Version: 5.4.0b3
3
+ Version: 5.5.0
4
4
  Summary: Pangea API SDK
5
5
  License: MIT
6
6
  Keywords: Pangea,SDK,Audit
@@ -9,13 +9,13 @@ Author-email: glenn.gallien@pangea.cloud
9
9
  Requires-Python: >=3.9,<4.0.0
10
10
  Classifier: Topic :: Software Development
11
11
  Classifier: Topic :: Software Development :: Libraries
12
- Requires-Dist: aiohttp (>=3.11.11,<4.0.0)
12
+ Requires-Dist: aiohttp (>=3.11.12,<4.0.0)
13
13
  Requires-Dist: cryptography (>=43.0.3,<44.0.0)
14
- Requires-Dist: deprecated (>=1.2.15,<2.0.0)
15
- Requires-Dist: google-crc32c (>=1.5.0,<2.0.0)
16
- Requires-Dist: pydantic (>=2.10.5,<3.0.0)
17
- Requires-Dist: python-dateutil (>=2.9.0,<3.0.0)
18
- Requires-Dist: requests (>=2.31.0,<3.0.0)
14
+ Requires-Dist: deprecated (>=1.2.18,<2.0.0)
15
+ Requires-Dist: google-crc32c (>=1.6.0,<2.0.0)
16
+ Requires-Dist: pydantic (>=2.10.6,<3.0.0)
17
+ Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
18
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
19
19
  Requires-Dist: requests-toolbelt (>=1.0.0,<2.0.0)
20
20
  Requires-Dist: typing-extensions (>=4.12.2,<5.0.0)
21
21
  Description-Content-Type: text/markdown
@@ -63,13 +63,13 @@ the same compatibility guarantees as stable releases.
63
63
  Via pip:
64
64
 
65
65
  ```bash
66
- $ pip3 install pangea-sdk==5.4.0b2
66
+ $ pip3 install pangea-sdk==5.5.0b2
67
67
  ```
68
68
 
69
69
  Via poetry:
70
70
 
71
71
  ```bash
72
- $ poetry add pangea-sdk==5.4.0b2
72
+ $ poetry add pangea-sdk==5.5.0b2
73
73
  ```
74
74
 
75
75
  ## Usage
@@ -41,13 +41,13 @@ the same compatibility guarantees as stable releases.
41
41
  Via pip:
42
42
 
43
43
  ```bash
44
- $ pip3 install pangea-sdk==5.4.0b2
44
+ $ pip3 install pangea-sdk==5.5.0b2
45
45
  ```
46
46
 
47
47
  Via poetry:
48
48
 
49
49
  ```bash
50
- $ poetry add pangea-sdk==5.4.0b2
50
+ $ poetry add pangea-sdk==5.5.0b2
51
51
  ```
52
52
 
53
53
  ## Usage
@@ -1,4 +1,4 @@
1
- __version__ = "5.4.0beta3"
1
+ __version__ = "5.5.0"
2
2
 
3
3
  from pangea.asyncio.request import PangeaRequestAsync
4
4
  from pangea.config import PangeaConfig
@@ -0,0 +1,221 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import overload
4
+
5
+ from typing_extensions import TypeVar
6
+
7
+ from pangea.asyncio.services.base import ServiceBaseAsync
8
+ from pangea.config import PangeaConfig
9
+ from pangea.response import PangeaResponse
10
+ from pangea.services.ai_guard import LogFields, TextGuardResult
11
+
12
+ _T = TypeVar("_T")
13
+
14
+
15
+ class AIGuardAsync(ServiceBaseAsync):
16
+ """AI Guard service client.
17
+
18
+ Provides methods to interact with Pangea's AI Guard service.
19
+
20
+ Examples:
21
+ from pangea import PangeaConfig
22
+ from pangea.asyncio.services import AIGuardAsync
23
+
24
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
25
+ ai_guard = AIGuardAsync(token="pangea_token", config=config)
26
+ """
27
+
28
+ service_name = "ai-guard"
29
+
30
+ def __init__(
31
+ self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
32
+ ) -> None:
33
+ """
34
+ AI Guard service client.
35
+
36
+ Initializes a new AI Guard client.
37
+
38
+ Args:
39
+ token: Pangea API token.
40
+ config: Pangea service configuration.
41
+ logger_name: Logger name.
42
+ config_id: Configuration ID.
43
+
44
+ Examples:
45
+ from pangea import PangeaConfig
46
+ from pangea.asyncio.services import AIGuardAsync
47
+
48
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
49
+ ai_guard = AIGuardAsync(token="pangea_token", config=config)
50
+ """
51
+
52
+ super().__init__(token, config, logger_name, config_id)
53
+
54
+ @overload
55
+ async def guard_text(
56
+ self,
57
+ text: str,
58
+ *,
59
+ recipe: str | None = None,
60
+ debug: bool | None = None,
61
+ llm_info: str | None = None,
62
+ log_fields: LogFields | None = None,
63
+ ) -> PangeaResponse[TextGuardResult[None]]:
64
+ """
65
+ Text Guard for scanning LLM inputs and outputs
66
+
67
+ Analyze and redact text to avoid manipulation of the model, addition of
68
+ malicious content, and other undesirable data transfers.
69
+
70
+ OperationId: ai_guard_post_v1_text_guard
71
+
72
+ Args:
73
+ text: Text to be scanned by AI Guard for PII, sensitive data,
74
+ malicious content, and other data types defined by the
75
+ configuration. Supports processing up to 10KB of text.
76
+ recipe: Recipe key of a configuration of data types and settings
77
+ defined in the Pangea User Console. It specifies the rules that
78
+ are to be applied to the text, such as defang malicious URLs.
79
+ debug: Setting this value to true will provide a detailed analysis
80
+ of the text data
81
+ llm_info: Short string hint for the LLM Provider information
82
+ log_field: Additional fields to include in activity log
83
+
84
+ Examples:
85
+ response = await ai_guard.guard_text("text")
86
+ """
87
+
88
+ @overload
89
+ async def guard_text(
90
+ self,
91
+ *,
92
+ messages: _T,
93
+ recipe: str | None = None,
94
+ debug: bool | None = None,
95
+ llm_info: str | None = None,
96
+ log_fields: LogFields | None = None,
97
+ ) -> PangeaResponse[TextGuardResult[_T]]:
98
+ """
99
+ Text Guard for scanning LLM inputs and outputs
100
+
101
+ Analyze and redact text to avoid manipulation of the model, addition of
102
+ malicious content, and other undesirable data transfers.
103
+
104
+ OperationId: ai_guard_post_v1_text_guard
105
+
106
+ Args:
107
+ messages: Structured messages data to be scanned by AI Guard for
108
+ PII, sensitive data, malicious content, and other data types
109
+ defined by the configuration. Supports processing up to 10KB of
110
+ JSON text
111
+ recipe: Recipe key of a configuration of data types and settings
112
+ defined in the Pangea User Console. It specifies the rules that
113
+ are to be applied to the text, such as defang malicious URLs.
114
+ debug: Setting this value to true will provide a detailed analysis
115
+ of the text data
116
+ llm_info: Short string hint for the LLM Provider information
117
+ log_field: Additional fields to include in activity log
118
+
119
+ Examples:
120
+ response = await ai_guard.guard_text(messages=[{"role": "user", "content": "hello world"}])
121
+ """
122
+
123
+ @overload
124
+ async def guard_text(
125
+ self,
126
+ *,
127
+ llm_input: _T,
128
+ recipe: str | None = None,
129
+ debug: bool | None = None,
130
+ llm_info: str | None = None,
131
+ log_fields: LogFields | None = None,
132
+ ) -> PangeaResponse[TextGuardResult[_T]]:
133
+ """
134
+ Text Guard for scanning LLM inputs and outputs
135
+
136
+ Analyze and redact text to avoid manipulation of the model, addition of
137
+ malicious content, and other undesirable data transfers.
138
+
139
+ OperationId: ai_guard_post_v1_text_guard
140
+
141
+ Args:
142
+ llm_input: Structured full llm payload data to be scanned by AI
143
+ Guard for PII, sensitive data, malicious content, and other data
144
+ types defined by the configuration. Supports processing up to
145
+ 10KB of JSON text
146
+ recipe: Recipe key of a configuration of data types and settings
147
+ defined in the Pangea User Console. It specifies the rules that
148
+ are to be applied to the text, such as defang malicious URLs.
149
+ debug: Setting this value to true will provide a detailed analysis
150
+ of the text data
151
+ llm_info: Short string hint for the LLM Provider information
152
+ log_field: Additional fields to include in activity log
153
+
154
+ Examples:
155
+ response = await ai_guard.guard_text(
156
+ llm_input={"model": "gpt-4o", "messages": [{"role": "user", "content": "hello world"}]}
157
+ )
158
+ """
159
+
160
+ async def guard_text( # type: ignore[misc]
161
+ self,
162
+ text: str | None = None,
163
+ *,
164
+ messages: _T | None = None,
165
+ llm_input: _T | None = None,
166
+ recipe: str | None = None,
167
+ debug: bool | None = None,
168
+ llm_info: str | None = None,
169
+ log_fields: LogFields | None = None,
170
+ ) -> PangeaResponse[TextGuardResult[None]]:
171
+ """
172
+ Text Guard for scanning LLM inputs and outputs
173
+
174
+ Analyze and redact text to avoid manipulation of the model, addition of
175
+ malicious content, and other undesirable data transfers.
176
+
177
+ OperationId: ai_guard_post_v1_text_guard
178
+
179
+ Args:
180
+ text: Text to be scanned by AI Guard for PII, sensitive data,
181
+ malicious content, and other data types defined by the
182
+ configuration. Supports processing up to 10KB of text.
183
+ messages: Structured messages data to be scanned by AI Guard for
184
+ PII, sensitive data, malicious content, and other data types
185
+ defined by the configuration. Supports processing up to 10KB of
186
+ JSON text
187
+ llm_input: Structured full llm payload data to be scanned by AI
188
+ Guard for PII, sensitive data, malicious content, and other data
189
+ types defined by the configuration. Supports processing up to
190
+ 10KB of JSON text
191
+ recipe: Recipe key of a configuration of data types and settings
192
+ defined in the Pangea User Console. It specifies the rules that
193
+ are to be applied to the text, such as defang malicious URLs.
194
+ debug: Setting this value to true will provide a detailed analysis
195
+ of the text data
196
+ llm_info: Short string hint for the LLM Provider information
197
+ log_field: Additional fields to include in activity log
198
+
199
+ Examples:
200
+ response = await ai_guard.guard_text("text")
201
+ """
202
+
203
+ if not any((text, messages, llm_input)):
204
+ raise ValueError("Exactly one of `text`, `messages`, or `llm_input` must be given")
205
+
206
+ if sum((text is not None, messages is not None, llm_input is not None)) > 1:
207
+ raise ValueError("Only one of `text`, `messages`, or `llm_input` can be given at once")
208
+
209
+ return await self.request.post(
210
+ "v1/text/guard",
211
+ TextGuardResult,
212
+ data={
213
+ "text": text,
214
+ "messages": messages,
215
+ "llm_input": llm_input,
216
+ "recipe": recipe,
217
+ "debug": debug,
218
+ "llm_info": llm_info,
219
+ "log_fields": log_fields,
220
+ },
221
+ )
@@ -52,20 +52,24 @@ class PromptGuardAsync(ServiceBaseAsync):
52
52
  super().__init__(token, config, logger_name, config_id)
53
53
 
54
54
  async def guard(
55
- self, messages: Iterable[Message], *, analyzers: Iterable[str] | None = None
55
+ self,
56
+ messages: Iterable[Message],
57
+ *,
58
+ analyzers: Iterable[str] | None = None,
59
+ classify: bool | None = None,
56
60
  ) -> PangeaResponse[GuardResult]:
57
61
  """
58
- Guard (Beta)
62
+ Guard
59
63
 
60
64
  Guard messages.
61
65
 
62
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
63
-
64
- OperationId: prompt_guard_post_v1beta_guard
66
+ OperationId: prompt_guard_post_v1_guard
65
67
 
66
68
  Args:
67
- messages: Messages.
68
- analyzers: Specific analyzers to be used in the call.
69
+ messages: Prompt content and role array in JSON format. The
70
+ `content` is the text that will be analyzed for redaction.
71
+ analyzers: Specific analyzers to be used in the call
72
+ classify: Boolean to enable classification of the content
69
73
 
70
74
  Examples:
71
75
  from pangea.asyncio.services.prompt_guard import Message
@@ -73,4 +77,8 @@ class PromptGuardAsync(ServiceBaseAsync):
73
77
  response = await prompt_guard.guard([Message(role="user", content="hello world")])
74
78
  """
75
79
 
76
- return await self.request.post("v1beta/guard", GuardResult, data={"messages": messages, "analyzers": analyzers})
80
+ return await self.request.post(
81
+ "v1/guard",
82
+ GuardResult,
83
+ data={"messages": messages, "analyzers": analyzers, "classify": classify},
84
+ )
@@ -34,7 +34,7 @@ class ShareAsync(ServiceBaseAsync):
34
34
 
35
35
  Examples:
36
36
  config = PangeaConfig(domain="aws.us.pangea.cloud")
37
- authz = ShareAsync(token="pangea_token", config=config)
37
+ share = ShareAsync(token="pangea_token", config=config)
38
38
  """
39
39
 
40
40
  super().__init__(token, config, logger_name, config_id=config_id)
@@ -51,7 +51,7 @@ class ShareAsync(ServiceBaseAsync):
51
51
  A PangeaResponse. Available response fields can be found in our [API documentation](https://pangea.cloud/docs/api/share).
52
52
 
53
53
  Examples:
54
- response = share.buckets()
54
+ response = await share.buckets()
55
55
  """
56
56
 
57
57
  return await self.request.post("v1/buckets", m.BucketsResult)
@@ -2,7 +2,7 @@
2
2
  # Author: Pangea Cyber Corporation
3
3
 
4
4
  from dataclasses import dataclass
5
- from typing import Optional
5
+ from typing import Literal, Optional
6
6
 
7
7
 
8
8
  @dataclass
@@ -16,10 +16,12 @@ class PangeaConfig:
16
16
  scheme (http:// or https://), subdomain, domain and port.
17
17
  """
18
18
 
19
- environment: str = "production"
19
+ environment: Literal["production", "local"] = "production"
20
20
  """
21
- Used to generate service url.
22
- It should be only 'production' or 'local' in cases of particular services that can run locally as Redact.
21
+ Pangea environment, used to construct service URLs.
22
+
23
+ If set to "local", then `domain` must be the full host (i.e., hostname and
24
+ port) for the Pangea service that this `PangeaConfig` will be used for.
23
25
  """
24
26
 
25
27
  config_id: Optional[str] = None
@@ -0,0 +1,323 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Dict, Generic, List, Optional, TypeVar, overload
4
+
5
+ from pangea.config import PangeaConfig
6
+ from pangea.response import APIRequestModel, APIResponseModel, PangeaResponse, PangeaResponseResult
7
+ from pangea.services.base import ServiceBase
8
+
9
+
10
+ class LogFields(APIRequestModel):
11
+ """Additional fields to include in activity log"""
12
+
13
+ citations: Optional[str] = None
14
+ """Origin or source application of the event"""
15
+
16
+ extra_info: Optional[str] = None
17
+ """Stores supplementary details related to the event"""
18
+
19
+ model: Optional[str] = None
20
+ """Model used to perform the event"""
21
+
22
+ source: Optional[str] = None
23
+ """IP address of user or app or agent"""
24
+
25
+ tools: Optional[str] = None
26
+ """Tools used to perform the event"""
27
+
28
+
29
+ class AnalyzerResponse(APIResponseModel):
30
+ analyzer: str
31
+ confidence: float
32
+
33
+
34
+ class PromptInjectionResult(APIResponseModel):
35
+ action: str
36
+ analyzer_responses: List[AnalyzerResponse]
37
+ """Triggered prompt injection analyzers."""
38
+
39
+
40
+ class PiiEntity(APIResponseModel):
41
+ type: str
42
+ value: str
43
+ action: str
44
+ start_pos: Optional[int] = None
45
+
46
+
47
+ class PiiEntityResult(APIResponseModel):
48
+ entities: List[PiiEntity]
49
+
50
+
51
+ class MaliciousEntity(APIResponseModel):
52
+ type: str
53
+ value: str
54
+ action: str
55
+ start_pos: Optional[int] = None
56
+ raw: Optional[Dict[str, Any]] = None
57
+
58
+
59
+ class MaliciousEntityResult(APIResponseModel):
60
+ entities: List[MaliciousEntity]
61
+
62
+
63
+ class SecretsEntity(APIResponseModel):
64
+ type: str
65
+ value: str
66
+ action: str
67
+ start_pos: Optional[int] = None
68
+ redacted_value: Optional[str] = None
69
+
70
+
71
+ class SecretsEntityResult(APIResponseModel):
72
+ entities: List[SecretsEntity]
73
+
74
+
75
+ class LanguageDetectionResult(APIResponseModel):
76
+ language: str
77
+ action: str
78
+
79
+
80
+ class CodeDetectionResult(APIResponseModel):
81
+ language: str
82
+ action: str
83
+
84
+
85
+ _T = TypeVar("_T")
86
+
87
+
88
+ class TextGuardDetector(APIResponseModel, Generic[_T]):
89
+ detected: bool
90
+ data: Optional[_T] = None
91
+
92
+
93
+ class TextGuardDetectors(APIResponseModel):
94
+ prompt_injection: Optional[TextGuardDetector[PromptInjectionResult]] = None
95
+ pii_entity: Optional[TextGuardDetector[PiiEntityResult]] = None
96
+ malicious_entity: Optional[TextGuardDetector[MaliciousEntityResult]] = None
97
+ secrets_detection: Optional[TextGuardDetector[SecretsEntityResult]] = None
98
+ profanity_and_toxicity: Optional[TextGuardDetector[Any]] = None
99
+ custom_entity: Optional[TextGuardDetector[Any]] = None
100
+ language_detection: Optional[TextGuardDetector[LanguageDetectionResult]] = None
101
+ code_detection: Optional[TextGuardDetector[CodeDetectionResult]] = None
102
+
103
+
104
+ class TextGuardResult(PangeaResponseResult, Generic[_T]):
105
+ detectors: TextGuardDetectors
106
+ """Result of the recipe analyzing and input prompt."""
107
+
108
+ prompt_text: Optional[str] = None
109
+ """Updated prompt text, if applicable."""
110
+
111
+ prompt_messages: Optional[_T] = None
112
+ """Updated structured prompt, if applicable."""
113
+
114
+ blocked: bool
115
+
116
+
117
+ class AIGuard(ServiceBase):
118
+ """AI Guard service client.
119
+
120
+ Provides methods to interact with Pangea's AI Guard service.
121
+
122
+ Examples:
123
+ from pangea import PangeaConfig
124
+ from pangea.services import AIGuard
125
+
126
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
127
+ ai_guard = AIGuard(token="pangea_token", config=config)
128
+ """
129
+
130
+ service_name = "ai-guard"
131
+
132
+ def __init__(
133
+ self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
134
+ ) -> None:
135
+ """
136
+ AI Guard service client.
137
+
138
+ Initializes a new AI Guard client.
139
+
140
+ Args:
141
+ token: Pangea API token.
142
+ config: Pangea service configuration.
143
+ logger_name: Logger name.
144
+ config_id: Configuration ID.
145
+
146
+ Examples:
147
+ from pangea import PangeaConfig
148
+ from pangea.services import AIGuard
149
+
150
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
151
+ ai_guard = AIGuard(token="pangea_token", config=config)
152
+ """
153
+
154
+ super().__init__(token, config, logger_name, config_id)
155
+
156
+ @overload
157
+ def guard_text(
158
+ self,
159
+ text: str,
160
+ *,
161
+ recipe: str | None = None,
162
+ debug: bool | None = None,
163
+ llm_info: str | None = None,
164
+ log_fields: LogFields | None = None,
165
+ ) -> PangeaResponse[TextGuardResult[None]]:
166
+ """
167
+ Text Guard for scanning LLM inputs and outputs
168
+
169
+ Analyze and redact text to avoid manipulation of the model, addition of
170
+ malicious content, and other undesirable data transfers.
171
+
172
+ OperationId: ai_guard_post_v1_text_guard
173
+
174
+ Args:
175
+ text: Text to be scanned by AI Guard for PII, sensitive data,
176
+ malicious content, and other data types defined by the
177
+ configuration. Supports processing up to 10KB of text.
178
+ recipe: Recipe key of a configuration of data types and settings
179
+ defined in the Pangea User Console. It specifies the rules that
180
+ are to be applied to the text, such as defang malicious URLs.
181
+ debug: Setting this value to true will provide a detailed analysis
182
+ of the text data
183
+ llm_info: Short string hint for the LLM Provider information
184
+ log_field: Additional fields to include in activity log
185
+
186
+ Examples:
187
+ response = ai_guard.guard_text("text")
188
+ """
189
+
190
+ @overload
191
+ def guard_text(
192
+ self,
193
+ *,
194
+ messages: _T,
195
+ recipe: str | None = None,
196
+ debug: bool | None = None,
197
+ llm_info: str | None = None,
198
+ log_fields: LogFields | None = None,
199
+ ) -> PangeaResponse[TextGuardResult[_T]]:
200
+ """
201
+ Text Guard for scanning LLM inputs and outputs
202
+
203
+ Analyze and redact text to avoid manipulation of the model, addition of
204
+ malicious content, and other undesirable data transfers.
205
+
206
+ OperationId: ai_guard_post_v1_text_guard
207
+
208
+ Args:
209
+ messages: Structured messages data to be scanned by AI Guard for
210
+ PII, sensitive data, malicious content, and other data types
211
+ defined by the configuration. Supports processing up to 10KB of
212
+ JSON text
213
+ recipe: Recipe key of a configuration of data types and settings
214
+ defined in the Pangea User Console. It specifies the rules that
215
+ are to be applied to the text, such as defang malicious URLs.
216
+ debug: Setting this value to true will provide a detailed analysis
217
+ of the text data
218
+ llm_info: Short string hint for the LLM Provider information
219
+ log_field: Additional fields to include in activity log
220
+
221
+ Examples:
222
+ response = ai_guard.guard_text(messages=[{"role": "user", "content": "hello world"}])
223
+ """
224
+
225
+ @overload
226
+ def guard_text(
227
+ self,
228
+ *,
229
+ llm_input: _T,
230
+ recipe: str | None = None,
231
+ debug: bool | None = None,
232
+ llm_info: str | None = None,
233
+ log_fields: LogFields | None = None,
234
+ ) -> PangeaResponse[TextGuardResult[_T]]:
235
+ """
236
+ Text Guard for scanning LLM inputs and outputs
237
+
238
+ Analyze and redact text to avoid manipulation of the model, addition of
239
+ malicious content, and other undesirable data transfers.
240
+
241
+ OperationId: ai_guard_post_v1_text_guard
242
+
243
+ Args:
244
+ llm_input: Structured full llm payload data to be scanned by AI
245
+ Guard for PII, sensitive data, malicious content, and other data
246
+ types defined by the configuration. Supports processing up to
247
+ 10KB of JSON text
248
+ recipe: Recipe key of a configuration of data types and settings
249
+ defined in the Pangea User Console. It specifies the rules that
250
+ are to be applied to the text, such as defang malicious URLs.
251
+ debug: Setting this value to true will provide a detailed analysis
252
+ of the text data
253
+ llm_info: Short string hint for the LLM Provider information
254
+ log_field: Additional fields to include in activity log
255
+
256
+ Examples:
257
+ response = ai_guard.guard_text(
258
+ llm_input={"model": "gpt-4o", "messages": [{"role": "user", "content": "hello world"}]}
259
+ )
260
+ """
261
+
262
+ def guard_text( # type: ignore[misc]
263
+ self,
264
+ text: str | None = None,
265
+ *,
266
+ messages: _T | None = None,
267
+ llm_input: _T | None = None,
268
+ recipe: str | None = None,
269
+ debug: bool | None = None,
270
+ llm_info: str | None = None,
271
+ log_fields: LogFields | None = None,
272
+ ) -> PangeaResponse[TextGuardResult[None]]:
273
+ """
274
+ Text Guard for scanning LLM inputs and outputs
275
+
276
+ Analyze and redact text to avoid manipulation of the model, addition of
277
+ malicious content, and other undesirable data transfers.
278
+
279
+ OperationId: ai_guard_post_v1_text_guard
280
+
281
+ Args:
282
+ text: Text to be scanned by AI Guard for PII, sensitive data,
283
+ malicious content, and other data types defined by the
284
+ configuration. Supports processing up to 10KB of text.
285
+ messages: Structured messages data to be scanned by AI Guard for
286
+ PII, sensitive data, malicious content, and other data types
287
+ defined by the configuration. Supports processing up to 10KB of
288
+ JSON text
289
+ llm_input: Structured full llm payload data to be scanned by AI
290
+ Guard for PII, sensitive data, malicious content, and other data
291
+ types defined by the configuration. Supports processing up to
292
+ 10KB of JSON text
293
+ recipe: Recipe key of a configuration of data types and settings
294
+ defined in the Pangea User Console. It specifies the rules that
295
+ are to be applied to the text, such as defang malicious URLs.
296
+ debug: Setting this value to true will provide a detailed analysis
297
+ of the text data
298
+ llm_info: Short string hint for the LLM Provider information
299
+ log_field: Additional fields to include in activity log
300
+
301
+ Examples:
302
+ response = ai_guard.guard_text("text")
303
+ """
304
+
305
+ if not any((text, messages, llm_input)):
306
+ raise ValueError("At least one of `text`, `messages`, or `llm_input` must be given")
307
+
308
+ if sum((text is not None, messages is not None, llm_input is not None)) > 1:
309
+ raise ValueError("Only one of `text`, `messages`, or `llm_input` can be given at once")
310
+
311
+ return self.request.post(
312
+ "v1/text/guard",
313
+ TextGuardResult,
314
+ data={
315
+ "text": text,
316
+ "messages": messages,
317
+ "llm_input": llm_input,
318
+ "recipe": recipe,
319
+ "debug": debug,
320
+ "llm_info": llm_info,
321
+ "log_fields": log_fields,
322
+ },
323
+ )
@@ -19,8 +19,8 @@ class Classification(APIResponseModel):
19
19
  category: str
20
20
  """Classification category"""
21
21
 
22
- label: str
23
- """Classification label"""
22
+ detected: bool
23
+ """Classification detection result"""
24
24
 
25
25
  confidence: float
26
26
  """Confidence score for the classification"""
@@ -30,7 +30,7 @@ class GuardResult(PangeaResponseResult):
30
30
  detected: bool
31
31
  """Boolean response for if the prompt was considered malicious or not"""
32
32
 
33
- type: Optional[Literal["direct", "indirect"]] = None
33
+ type: Optional[Literal["direct", "indirect", ""]] = None
34
34
  """Type of analysis, either direct or indirect"""
35
35
 
36
36
  analyzer: Optional[str] = None
@@ -86,20 +86,24 @@ class PromptGuard(ServiceBase):
86
86
  super().__init__(token, config, logger_name, config_id)
87
87
 
88
88
  def guard(
89
- self, messages: Iterable[Message], *, analyzers: Iterable[str] | None = None
89
+ self,
90
+ messages: Iterable[Message],
91
+ *,
92
+ analyzers: Iterable[str] | None = None,
93
+ classify: bool | None = None,
90
94
  ) -> PangeaResponse[GuardResult]:
91
95
  """
92
- Guard (Beta)
96
+ Guard
93
97
 
94
98
  Guard messages.
95
99
 
96
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
97
-
98
- OperationId: prompt_guard_post_v1beta_guard
100
+ OperationId: prompt_guard_post_v1_guard
99
101
 
100
102
  Args:
101
- messages: Prompt content and role array.
102
- analyzers: Specific analyzers to be used in the call.
103
+ messages: Prompt content and role array in JSON format. The
104
+ `content` is the text that will be analyzed for redaction.
105
+ analyzers: Specific analyzers to be used in the call
106
+ classify: Boolean to enable classification of the content
103
107
 
104
108
  Examples:
105
109
  from pangea.services.prompt_guard import Message
@@ -107,4 +111,8 @@ class PromptGuard(ServiceBase):
107
111
  response = prompt_guard.guard([Message(role="user", content="hello world")])
108
112
  """
109
113
 
110
- return self.request.post("v1beta/guard", GuardResult, data={"messages": messages, "analyzers": analyzers})
114
+ return self.request.post(
115
+ "v1/guard",
116
+ GuardResult,
117
+ data={"messages": messages, "analyzers": analyzers, "classify": classify},
118
+ )
@@ -762,7 +762,7 @@ class Share(ServiceBase):
762
762
 
763
763
  Examples:
764
764
  config = PangeaConfig(domain="aws.us.pangea.cloud")
765
- authz = Share(token="pangea_token", config=config)
765
+ share = Share(token="pangea_token", config=config)
766
766
  """
767
767
 
768
768
  super().__init__(token, config, logger_name, config_id=config_id)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pangea-sdk"
3
- version = "5.4.0beta3"
3
+ version = "5.5.0"
4
4
  description = "Pangea API SDK"
5
5
  authors = [
6
6
  {name = "Glenn Gallien", email = "glenn.gallien@pangea.cloud"}
@@ -16,13 +16,13 @@ classifiers = [
16
16
  ]
17
17
  requires-python = ">=3.9,<4.0.0"
18
18
  dependencies = [
19
- "aiohttp (>=3.11.11,<4.0.0)",
19
+ "aiohttp (>=3.11.12,<4.0.0)",
20
20
  "cryptography (>=43.0.3,<44.0.0)",
21
- "deprecated (>=1.2.15,<2.0.0)",
22
- "google-crc32c (>=1.5.0,<2.0.0)",
23
- "pydantic (>=2.10.5,<3.0.0)",
24
- "python-dateutil (>=2.9.0,<3.0.0)",
25
- "requests (>=2.31.0,<3.0.0)",
21
+ "deprecated (>=1.2.18,<2.0.0)",
22
+ "google-crc32c (>=1.6.0,<2.0.0)",
23
+ "pydantic (>=2.10.6,<3.0.0)",
24
+ "python-dateutil (>=2.9.0.post0,<3.0.0)",
25
+ "requests (>=2.32.3,<3.0.0)",
26
26
  "requests-toolbelt (>=1.0.0,<2.0.0)",
27
27
  "typing-extensions (>=4.12.2,<5.0.0)"
28
28
  ]
@@ -33,10 +33,10 @@ packages = [
33
33
  ]
34
34
 
35
35
  [tool.poetry.group.dev.dependencies]
36
- black = "^24.10.0"
36
+ black = "^25.1.0"
37
37
  docstring-parser = "^0.15"
38
- isort = "^5.13.2"
39
- mypy = "1.14.1"
38
+ isort = "^6.0.0"
39
+ mypy = "1.15.0"
40
40
  types-Deprecated = "^1.2.9.3"
41
41
  types-python-dateutil = "^2.8.19.14"
42
42
  types-requests = "^2.31.0.10"
@@ -1,75 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pangea.asyncio.services.base import ServiceBaseAsync
4
- from pangea.config import PangeaConfig
5
- from pangea.response import PangeaResponse
6
- from pangea.services.ai_guard import TextGuardResult
7
-
8
-
9
- class AIGuardAsync(ServiceBaseAsync):
10
- """AI Guard service client.
11
-
12
- Provides methods to interact with Pangea's AI Guard service.
13
-
14
- Examples:
15
- from pangea import PangeaConfig
16
- from pangea.asyncio.services import AIGuardAsync
17
-
18
- config = PangeaConfig(domain="aws.us.pangea.cloud")
19
- ai_guard = AIGuardAsync(token="pangea_token", config=config)
20
- """
21
-
22
- service_name = "ai-guard"
23
-
24
- def __init__(
25
- self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
26
- ) -> None:
27
- """
28
- AI Guard service client.
29
-
30
- Initializes a new AI Guard client.
31
-
32
- Args:
33
- token: Pangea API token.
34
- config: Pangea service configuration.
35
- logger_name: Logger name.
36
- config_id: Configuration ID.
37
-
38
- Examples:
39
- from pangea import PangeaConfig
40
- from pangea.asyncio.services import AIGuardAsync
41
-
42
- config = PangeaConfig(domain="aws.us.pangea.cloud")
43
- ai_guard = AIGuardAsync(token="pangea_token", config=config)
44
- """
45
-
46
- super().__init__(token, config, logger_name, config_id)
47
-
48
- async def guard_text(
49
- self,
50
- text: str,
51
- *,
52
- recipe: str = "pangea_prompt_guard",
53
- debug: bool = False,
54
- ) -> PangeaResponse[TextGuardResult]:
55
- """
56
- Text guard (Beta)
57
-
58
- Guard text.
59
-
60
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
61
-
62
- OperationId: ai_guard_post_v1beta_text_guard
63
-
64
- Args:
65
- text: Text.
66
- recipe: Recipe.
67
- debug: Debug.
68
-
69
- Examples:
70
- response = await ai_guard.guard_text("text")
71
- """
72
-
73
- return await self.request.post(
74
- "v1beta/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
75
- )
@@ -1,128 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import Any, Dict, Generic, List, Optional, TypeVar
4
-
5
- from pangea.config import PangeaConfig
6
- from pangea.response import APIResponseModel, PangeaResponse, PangeaResponseResult
7
- from pangea.services.base import ServiceBase
8
-
9
-
10
- class AnalyzerResponse(APIResponseModel):
11
- analyzer: str
12
- confidence: float
13
-
14
-
15
- class PromptInjectionResult(APIResponseModel):
16
- analyzer_responses: List[AnalyzerResponse]
17
- """Triggered prompt injection analyzers."""
18
-
19
-
20
- class PiiEntity(APIResponseModel):
21
- type: str
22
- value: str
23
- redacted: bool
24
- start_pos: Optional[int] = None
25
-
26
-
27
- class PiiEntityResult(APIResponseModel):
28
- entities: List[PiiEntity]
29
-
30
-
31
- class MaliciousEntity(APIResponseModel):
32
- type: str
33
- value: str
34
- redacted: Optional[bool] = None
35
- start_pos: Optional[int] = None
36
- raw: Optional[Dict[str, Any]] = None
37
-
38
-
39
- class MaliciousEntityResult(APIResponseModel):
40
- entities: List[MaliciousEntity]
41
-
42
-
43
- T = TypeVar("T")
44
-
45
-
46
- class TextGuardDetector(APIResponseModel, Generic[T]):
47
- detected: bool
48
- data: Optional[T] = None
49
-
50
-
51
- class TextGuardDetectors(APIResponseModel):
52
- prompt_injection: Optional[TextGuardDetector[PromptInjectionResult]] = None
53
- pii_entity: Optional[TextGuardDetector[PiiEntityResult]] = None
54
- malicious_entity: Optional[TextGuardDetector[MaliciousEntityResult]] = None
55
-
56
-
57
- class TextGuardResult(PangeaResponseResult):
58
- detectors: TextGuardDetectors
59
- prompt: str
60
-
61
-
62
- class AIGuard(ServiceBase):
63
- """AI Guard service client.
64
-
65
- Provides methods to interact with Pangea's AI Guard service.
66
-
67
- Examples:
68
- from pangea import PangeaConfig
69
- from pangea.services import AIGuard
70
-
71
- config = PangeaConfig(domain="aws.us.pangea.cloud")
72
- ai_guard = AIGuard(token="pangea_token", config=config)
73
- """
74
-
75
- service_name = "ai-guard"
76
-
77
- def __init__(
78
- self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
79
- ) -> None:
80
- """
81
- AI Guard service client.
82
-
83
- Initializes a new AI Guard client.
84
-
85
- Args:
86
- token: Pangea API token.
87
- config: Pangea service configuration.
88
- logger_name: Logger name.
89
- config_id: Configuration ID.
90
-
91
- Examples:
92
- from pangea import PangeaConfig
93
- from pangea.services import AIGuard
94
-
95
- config = PangeaConfig(domain="aws.us.pangea.cloud")
96
- ai_guard = AIGuard(token="pangea_token", config=config)
97
- """
98
-
99
- super().__init__(token, config, logger_name, config_id)
100
-
101
- def guard_text(
102
- self,
103
- text: str,
104
- *,
105
- recipe: str = "pangea_prompt_guard",
106
- debug: bool = False,
107
- ) -> PangeaResponse[TextGuardResult]:
108
- """
109
- Text guard (Beta)
110
-
111
- Guard text.
112
-
113
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
114
-
115
- OperationId: ai_guard_post_v1beta_text_guard
116
-
117
- Args:
118
- text: Text.
119
- recipe: Recipe.
120
- debug: Debug.
121
-
122
- Examples:
123
- response = ai_guard.guard_text("text")
124
- """
125
-
126
- return self.request.post(
127
- "v1beta/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
128
- )
File without changes
File without changes
File without changes