pangea-sdk 5.4.0b3__py3-none-any.whl → 5.5.0b2__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.
pangea/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "5.4.0beta3"
1
+ __version__ = "5.5.0beta2"
2
2
 
3
3
  from pangea.asyncio.request import PangeaRequestAsync
4
4
  from pangea.config import PangeaConfig
@@ -1,10 +1,16 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from typing import overload
4
+
5
+ from typing_extensions import TypeVar
6
+
3
7
  from pangea.asyncio.services.base import ServiceBaseAsync
4
8
  from pangea.config import PangeaConfig
5
9
  from pangea.response import PangeaResponse
6
10
  from pangea.services.ai_guard import TextGuardResult
7
11
 
12
+ _T = TypeVar("_T")
13
+
8
14
 
9
15
  class AIGuardAsync(ServiceBaseAsync):
10
16
  """AI Guard service client.
@@ -45,31 +51,106 @@ class AIGuardAsync(ServiceBaseAsync):
45
51
 
46
52
  super().__init__(token, config, logger_name, config_id)
47
53
 
54
+ @overload
48
55
  async def guard_text(
49
56
  self,
50
- text: str,
57
+ text_or_messages: str,
51
58
  *,
52
59
  recipe: str = "pangea_prompt_guard",
53
60
  debug: bool = False,
54
- ) -> PangeaResponse[TextGuardResult]:
61
+ ) -> PangeaResponse[TextGuardResult[None]]:
55
62
  """
56
- Text guard (Beta)
63
+ Text Guard for scanning LLM inputs and outputs (Beta)
57
64
 
58
- Guard text.
65
+ Analyze and redact text to avoid manipulation of the model, addition of
66
+ malicious content, and other undesirable data transfers.
59
67
 
60
68
  How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
61
69
 
62
70
  OperationId: ai_guard_post_v1beta_text_guard
63
71
 
64
72
  Args:
65
- text: Text.
66
- recipe: Recipe.
67
- debug: Debug.
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
68
81
 
69
82
  Examples:
70
83
  response = await ai_guard.guard_text("text")
71
84
  """
72
85
 
86
+ @overload
87
+ async def guard_text(
88
+ self,
89
+ text_or_messages: _T,
90
+ *,
91
+ recipe: str = "pangea_prompt_guard",
92
+ debug: bool = False,
93
+ ) -> PangeaResponse[TextGuardResult[_T]]:
94
+ """
95
+ Text Guard for scanning LLM inputs and outputs (Beta)
96
+
97
+ Analyze and redact text to avoid manipulation of the model, addition of
98
+ malicious content, and other undesirable data transfers.
99
+
100
+ How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
101
+
102
+ OperationId: ai_guard_post_v1beta_text_guard
103
+
104
+ Args:
105
+ text_or_messages: Structured data to be scanned by AI Guard for PII,
106
+ sensitive data, malicious content, and other data types defined
107
+ by the configuration. Supports processing up to 10KB of text.
108
+ recipe: Recipe key of a configuration of data types and settings
109
+ defined in the Pangea User Console. It specifies the rules that
110
+ are to be applied to the text, such as defang malicious URLs.
111
+ debug: Setting this value to true will provide a detailed analysis
112
+ of the text data
113
+
114
+ Examples:
115
+ response = await ai_guard.guard_text([
116
+ {"role": "user", "content": "hello world"}
117
+ ])
118
+ """
119
+
120
+ async def guard_text(
121
+ self,
122
+ text_or_messages: str | _T,
123
+ *,
124
+ recipe: str = "pangea_prompt_guard",
125
+ debug: bool = False,
126
+ ) -> PangeaResponse[TextGuardResult[_T]]:
127
+ """
128
+ Text Guard for scanning LLM inputs and outputs (Beta)
129
+
130
+ Analyze and redact text to avoid manipulation of the model, addition of
131
+ malicious content, and other undesirable data transfers.
132
+
133
+ How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
134
+
135
+ OperationId: ai_guard_post_v1beta_text_guard
136
+
137
+ Args:
138
+ text_or_messages: Text or structured data to be scanned by AI Guard
139
+ for PII, sensitive data, malicious content, and other data types
140
+ defined by the configuration. Supports processing up to 10KB of text.
141
+ recipe: Recipe key of a configuration of data types and settings
142
+ defined in the Pangea User Console. It specifies the rules that
143
+ are to be applied to the text, such as defang malicious URLs.
144
+ debug: Setting this value to true will provide a detailed analysis
145
+ of the text data
146
+ """
147
+
73
148
  return await self.request.post(
74
- "v1beta/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
149
+ "v1beta/text/guard",
150
+ TextGuardResult,
151
+ data={
152
+ "text" if isinstance(text_or_messages, str) else "messages": text_or_messages,
153
+ "recipe": recipe,
154
+ "debug": debug,
155
+ },
75
156
  )
pangea/config.py CHANGED
@@ -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
@@ -1,11 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Any, Dict, Generic, List, Optional, TypeVar
3
+ from typing import Any, Dict, Generic, List, Literal, Optional, TypeVar, overload
4
4
 
5
5
  from pangea.config import PangeaConfig
6
6
  from pangea.response import APIResponseModel, PangeaResponse, PangeaResponseResult
7
7
  from pangea.services.base import ServiceBase
8
8
 
9
+ _DetectorAction = Literal["detected", "redacted", "defanged", "reported", "blocked"]
10
+
9
11
 
10
12
  class AnalyzerResponse(APIResponseModel):
11
13
  analyzer: str
@@ -13,6 +15,7 @@ class AnalyzerResponse(APIResponseModel):
13
15
 
14
16
 
15
17
  class PromptInjectionResult(APIResponseModel):
18
+ action: _DetectorAction
16
19
  analyzer_responses: List[AnalyzerResponse]
17
20
  """Triggered prompt injection analyzers."""
18
21
 
@@ -20,7 +23,7 @@ class PromptInjectionResult(APIResponseModel):
20
23
  class PiiEntity(APIResponseModel):
21
24
  type: str
22
25
  value: str
23
- redacted: bool
26
+ action: _DetectorAction
24
27
  start_pos: Optional[int] = None
25
28
 
26
29
 
@@ -31,7 +34,7 @@ class PiiEntityResult(APIResponseModel):
31
34
  class MaliciousEntity(APIResponseModel):
32
35
  type: str
33
36
  value: str
34
- redacted: Optional[bool] = None
37
+ action: _DetectorAction
35
38
  start_pos: Optional[int] = None
36
39
  raw: Optional[Dict[str, Any]] = None
37
40
 
@@ -40,23 +43,58 @@ class MaliciousEntityResult(APIResponseModel):
40
43
  entities: List[MaliciousEntity]
41
44
 
42
45
 
43
- T = TypeVar("T")
46
+ class SecretsEntity(APIResponseModel):
47
+ type: str
48
+ value: str
49
+ action: _DetectorAction
50
+ start_pos: Optional[int] = None
51
+ redacted_value: Optional[str] = None
52
+
53
+
54
+ class SecretsEntityResult(APIResponseModel):
55
+ entities: List[SecretsEntity]
56
+
57
+
58
+ class LanguageDetectionResult(APIResponseModel):
59
+ language: str
60
+ action: _DetectorAction
61
+
62
+
63
+ class CodeDetectionResult(APIResponseModel):
64
+ language: str
65
+ action: _DetectorAction
66
+
67
+
68
+ _T = TypeVar("_T")
44
69
 
45
70
 
46
- class TextGuardDetector(APIResponseModel, Generic[T]):
71
+ class TextGuardDetector(APIResponseModel, Generic[_T]):
47
72
  detected: bool
48
- data: Optional[T] = None
73
+ data: Optional[_T] = None
49
74
 
50
75
 
51
76
  class TextGuardDetectors(APIResponseModel):
52
77
  prompt_injection: Optional[TextGuardDetector[PromptInjectionResult]] = None
53
78
  pii_entity: Optional[TextGuardDetector[PiiEntityResult]] = None
54
79
  malicious_entity: Optional[TextGuardDetector[MaliciousEntityResult]] = None
80
+ secrets_detection: Optional[TextGuardDetector[SecretsEntityResult]] = None
81
+ profanity_and_toxicity: Optional[TextGuardDetector[Any]] = None
82
+ custom_entity: Optional[TextGuardDetector[Any]] = None
83
+ language_detection: Optional[TextGuardDetector[LanguageDetectionResult]] = None
84
+ code_detection: Optional[TextGuardDetector[CodeDetectionResult]] = None
55
85
 
56
86
 
57
- class TextGuardResult(PangeaResponseResult):
87
+ class TextGuardResult(PangeaResponseResult, Generic[_T]):
58
88
  detectors: TextGuardDetectors
59
- prompt: str
89
+ """Result of the recipe analyzing and input prompt."""
90
+
91
+ prompt_text: Optional[str] = None
92
+ """Updated prompt text, if applicable."""
93
+
94
+ prompt_messages: Optional[_T] = None
95
+ """Updated structured prompt, if applicable."""
96
+
97
+ blocked: bool
60
98
 
61
99
 
62
100
  class AIGuard(ServiceBase):
@@ -98,31 +136,106 @@ class AIGuard(ServiceBase):
98
136
 
99
137
  super().__init__(token, config, logger_name, config_id)
100
138
 
139
+ @overload
101
140
  def guard_text(
102
141
  self,
103
- text: str,
142
+ text_or_messages: str,
104
143
  *,
105
144
  recipe: str = "pangea_prompt_guard",
106
145
  debug: bool = False,
107
- ) -> PangeaResponse[TextGuardResult]:
146
+ ) -> PangeaResponse[TextGuardResult[None]]:
108
147
  """
109
- Text guard (Beta)
148
+ Text Guard for scanning LLM inputs and outputs (Beta)
110
149
 
111
- Guard text.
150
+ Analyze and redact text to avoid manipulation of the model, addition of
151
+ malicious content, and other undesirable data transfers.
112
152
 
113
153
  How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
114
154
 
115
155
  OperationId: ai_guard_post_v1beta_text_guard
116
156
 
117
157
  Args:
118
- text: Text.
119
- recipe: Recipe.
120
- debug: Debug.
158
+ text: Text to be scanned by AI Guard for PII, sensitive data,
159
+ malicious content, and other data types defined by the
160
+ configuration. Supports processing up to 10KB of text.
161
+ recipe: Recipe key of a configuration of data types and settings
162
+ defined in the Pangea User Console. It specifies the rules that
163
+ are to be applied to the text, such as defang malicious URLs.
164
+ debug: Setting this value to true will provide a detailed analysis
165
+ of the text data
121
166
 
122
167
  Examples:
123
168
  response = ai_guard.guard_text("text")
124
169
  """
125
170
 
171
+ @overload
172
+ def guard_text(
173
+ self,
174
+ text_or_messages: _T,
175
+ *,
176
+ recipe: str = "pangea_prompt_guard",
177
+ debug: bool = False,
178
+ ) -> PangeaResponse[TextGuardResult[_T]]:
179
+ """
180
+ Text Guard for scanning LLM inputs and outputs (Beta)
181
+
182
+ Analyze and redact text to avoid manipulation of the model, addition of
183
+ malicious content, and other undesirable data transfers.
184
+
185
+ How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
186
+
187
+ OperationId: ai_guard_post_v1beta_text_guard
188
+
189
+ Args:
190
+ text_or_messages: Structured data to be scanned by AI Guard for PII,
191
+ sensitive data, malicious content, and other data types defined
192
+ by the configuration. Supports processing up to 10KB of text.
193
+ recipe: Recipe key of a configuration of data types and settings
194
+ defined in the Pangea User Console. It specifies the rules that
195
+ are to be applied to the text, such as defang malicious URLs.
196
+ debug: Setting this value to true will provide a detailed analysis
197
+ of the text data
198
+
199
+ Examples:
200
+ response = ai_guard.guard_text([
201
+ {"role": "user", "content": "hello world"}
202
+ ])
203
+ """
204
+
205
+ def guard_text(
206
+ self,
207
+ text_or_messages: str | _T,
208
+ *,
209
+ recipe: str = "pangea_prompt_guard",
210
+ debug: bool = False,
211
+ ) -> PangeaResponse[TextGuardResult[_T]]:
212
+ """
213
+ Text Guard for scanning LLM inputs and outputs (Beta)
214
+
215
+ Analyze and redact text to avoid manipulation of the model, addition of
216
+ malicious content, and other undesirable data transfers.
217
+
218
+ How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
219
+
220
+ OperationId: ai_guard_post_v1beta_text_guard
221
+
222
+ Args:
223
+ text_or_messages: Text or structured data to be scanned by AI Guard
224
+ for PII, sensitive data, malicious content, and other data types
225
+ defined by the configuration. Supports processing up to 10KB of text.
226
+ recipe: Recipe key of a configuration of data types and settings
227
+ defined in the Pangea User Console. It specifies the rules that
228
+ are to be applied to the text, such as defang malicious URLs.
229
+ debug: Setting this value to true will provide a detailed analysis
230
+ of the text data
231
+ """
232
+
126
233
  return self.request.post(
127
- "v1beta/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
234
+ "v1beta/text/guard",
235
+ TextGuardResult,
236
+ data={
237
+ "text" if isinstance(text_or_messages, str) else "messages": text_or_messages,
238
+ "recipe": recipe,
239
+ "debug": debug,
240
+ },
128
241
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pangea-sdk
3
- Version: 5.4.0b3
3
+ Version: 5.5.0b2
4
4
  Summary: Pangea API SDK
5
5
  License: MIT
6
6
  Keywords: Pangea,SDK,Audit
@@ -14,7 +14,7 @@ Requires-Dist: cryptography (>=43.0.3,<44.0.0)
14
14
  Requires-Dist: deprecated (>=1.2.15,<2.0.0)
15
15
  Requires-Dist: google-crc32c (>=1.5.0,<2.0.0)
16
16
  Requires-Dist: pydantic (>=2.10.5,<3.0.0)
17
- Requires-Dist: python-dateutil (>=2.9.0,<3.0.0)
17
+ Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
18
18
  Requires-Dist: requests (>=2.31.0,<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)
@@ -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
@@ -1,9 +1,9 @@
1
- pangea/__init__.py,sha256=29EDBUe0NL5ld5Z2H45IPiiHbf_itVE1apzuRpGlQlE,251
1
+ pangea/__init__.py,sha256=KVhhIk-3aH5cvqxWeNcQMIHkrdG5FrODbZ9AG2Sj8ds,251
2
2
  pangea/asyncio/__init__.py,sha256=kjEMkqMQ521LlMSu5jn3_WgweyArwVZ2C-s3x7mR6Pk,45
3
3
  pangea/asyncio/file_uploader.py,sha256=wI7epib7Rc5jtZw4eJ1L1SlmutDG6CPv59C8N2UPhtY,1436
4
4
  pangea/asyncio/request.py,sha256=lpLY-o405r3-VUfrAE5uxYxI8UjM4hjPqUzAUtOGE5o,18040
5
5
  pangea/asyncio/services/__init__.py,sha256=L6Tdhjfx_ZECHskhLMPaCcOefi-r-imw6q_zlU4j-FY,464
6
- pangea/asyncio/services/ai_guard.py,sha256=FxO8GRBztfOhpd7Kzj4-jWAiG0kb89-jVWL_AnbEou8,2142
6
+ pangea/asyncio/services/ai_guard.py,sha256=GNDXooxEvEkifNef9sPBaM6ymlwdogto6oLPf10gPgo,5601
7
7
  pangea/asyncio/services/audit.py,sha256=rPaCx4cMzj-g9WFMRIysFCJAz6Btp6YrhcKe_exky8k,26283
8
8
  pangea/asyncio/services/authn.py,sha256=rPeLJweL8mYH_t4ebcQn4n_Wglr3kClKNnCXNCimZU4,46622
9
9
  pangea/asyncio/services/authz.py,sha256=B_0_nhDMJcjNpjpCx3Vi2LDRhlmfV9325GKbUZ8reos,10025
@@ -17,7 +17,7 @@ pangea/asyncio/services/sanitize.py,sha256=EbSdq_v9yZWce9xEYWvZharE9bJcxw8cg5Pv8
17
17
  pangea/asyncio/services/share.py,sha256=AXXtFtmbXud0dAAom7qqHVOK9zBfX5S10MFS_1DQvio,30767
18
18
  pangea/asyncio/services/vault.py,sha256=VqrJGSEdq6MlZRI6cJpkthhIsqLClSQdgVxwYCbIwEk,77079
19
19
  pangea/audit_logger.py,sha256=gRkCfUUT5LDNaycwxkhZUySgY47jDfn1ZeKOul4XCQI,3842
20
- pangea/config.py,sha256=mQUu8GX_6weIuv3vjNdG5plppXskXYASmxMWtFQh-hc,1662
20
+ pangea/config.py,sha256=qe1ZhvDxNQxNXUpAtzF6nPLjyRpPVG9sjhLZV6Pkyn8,1766
21
21
  pangea/crypto/rsa.py,sha256=mwSiNy571KAGr3F6oEM0CXWkl9D023ch8ldbZZeLj_4,4747
22
22
  pangea/deep_verify.py,sha256=ZGraaL7TCxwRBIDqjBFR0clKlhAC-Yce6kD-1LClhG8,8616
23
23
  pangea/deprecated.py,sha256=IjFYEVvY1E0ld0SMkEYC1o62MAleX3nnT1If2dFVbHo,608
@@ -28,7 +28,7 @@ pangea/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  pangea/request.py,sha256=vGB8owXUiNQoeiiACFvfXvg44JJo_L6WfcHlF6ug8co,25082
29
29
  pangea/response.py,sha256=lPAcYsF9Xg166CiyhCofVmQA-W4jevh0MQXxUa8Re68,7737
30
30
  pangea/services/__init__.py,sha256=h36HzyIGaI5kO6l3UCwKHx_Kd-m_9mYVwn5MLRVzblI,408
31
- pangea/services/ai_guard.py,sha256=-Ztyf9WUo1EB-gRzVH--OU62xzPoeVQ7BiFMTGUK5fI,3303
31
+ pangea/services/ai_guard.py,sha256=sx2OYRxxVim2br4UorPAYrT3paidqzvy-dSyept-6SA,7860
32
32
  pangea/services/audit/audit.py,sha256=7-c9l7jyGtpG7SqRUMpqsAzcUDhMZ5izgPalxHXsUvM,39320
33
33
  pangea/services/audit/exceptions.py,sha256=bhVuYe4ammacOVxwg98CChxvwZf5FKgR2DcgqILOcwc,471
34
34
  pangea/services/audit/models.py,sha256=1h1B9eSYQMYG3f8WNi1UcDX2-impRrET_ErjJYUnj7M,14678
@@ -55,6 +55,6 @@ pangea/services/vault/vault.py,sha256=ow-Zm7PYzfWIfUcA4UNnpeL2DHfZM4C7inRDmNR3zQ
55
55
  pangea/tools.py,sha256=2-Y4SAHWFv6Ocj42J_bWrVy27M5G3wi7a8LJn0dabHc,6427
56
56
  pangea/utils.py,sha256=dZ6MwFVEWXUgXvvDg-k6JnvVfsgslvtaBd7ez7afrqk,4983
57
57
  pangea/verify_audit.py,sha256=nSP17OzoSPdvezRExwfcf45H8ZPZnxZu-CbEp3qFJO0,17354
58
- pangea_sdk-5.4.0b3.dist-info/METADATA,sha256=Efq0uLcKHqWNCAKNQGFcsuiWIzbcmAzrhEMekwNaYTg,7011
59
- pangea_sdk-5.4.0b3.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
60
- pangea_sdk-5.4.0b3.dist-info/RECORD,,
58
+ pangea_sdk-5.5.0b2.dist-info/METADATA,sha256=QyRMHqmhVmQzTmhzY604kC_A76ADHX3fQnXzhklMrPE,7017
59
+ pangea_sdk-5.5.0b2.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
60
+ pangea_sdk-5.5.0b2.dist-info/RECORD,,