pangea-sdk 5.3.0__tar.gz → 5.4.0b2__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 (60) hide show
  1. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/PKG-INFO +3 -3
  2. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/README.md +2 -2
  3. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/__init__.py +1 -1
  4. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/request.py +12 -4
  5. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/__init__.py +2 -0
  6. pangea_sdk-5.4.0b2/pangea/asyncio/services/ai_guard.py +75 -0
  7. pangea_sdk-5.4.0b2/pangea/asyncio/services/prompt_guard.py +76 -0
  8. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/sanitize.py +1 -1
  9. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/request.py +9 -1
  10. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/__init__.py +2 -0
  11. pangea_sdk-5.4.0b2/pangea/services/ai_guard.py +128 -0
  12. pangea_sdk-5.4.0b2/pangea/services/prompt_guard.py +110 -0
  13. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/sanitize.py +1 -18
  14. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pyproject.toml +2 -2
  15. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/__init__.py +0 -0
  16. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/file_uploader.py +0 -0
  17. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/audit.py +0 -0
  18. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/authn.py +0 -0
  19. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/authz.py +0 -0
  20. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/base.py +0 -0
  21. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/embargo.py +0 -0
  22. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/file_scan.py +0 -0
  23. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/intel.py +0 -0
  24. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/redact.py +0 -0
  25. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/share.py +0 -0
  26. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/asyncio/services/vault.py +0 -0
  27. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/audit_logger.py +0 -0
  28. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/config.py +0 -0
  29. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/crypto/rsa.py +0 -0
  30. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/deep_verify.py +0 -0
  31. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/deprecated.py +0 -0
  32. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/dump_audit.py +0 -0
  33. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/exceptions.py +0 -0
  34. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/file_uploader.py +0 -0
  35. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/py.typed +0 -0
  36. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/response.py +0 -0
  37. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/audit/audit.py +0 -0
  38. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/audit/exceptions.py +0 -0
  39. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/audit/models.py +0 -0
  40. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/audit/signing.py +0 -0
  41. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/audit/util.py +0 -0
  42. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/authn/authn.py +0 -0
  43. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/authn/models.py +0 -0
  44. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/authz.py +0 -0
  45. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/base.py +0 -0
  46. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/embargo.py +0 -0
  47. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/file_scan.py +0 -0
  48. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/intel.py +0 -0
  49. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/redact.py +0 -0
  50. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/share/file_format.py +0 -0
  51. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/share/share.py +0 -0
  52. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/vault/models/asymmetric.py +0 -0
  53. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/vault/models/common.py +0 -0
  54. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/vault/models/keys.py +0 -0
  55. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/vault/models/secret.py +0 -0
  56. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/vault/models/symmetric.py +0 -0
  57. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/services/vault/vault.py +0 -0
  58. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/tools.py +0 -0
  59. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/utils.py +0 -0
  60. {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b2}/pangea/verify_audit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pangea-sdk
3
- Version: 5.3.0
3
+ Version: 5.4.0b2
4
4
  Summary: Pangea API SDK
5
5
  License: MIT
6
6
  Keywords: Pangea,SDK,Audit
@@ -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.2.0b2
66
+ $ pip3 install pangea-sdk==5.4.0b2
67
67
  ```
68
68
 
69
69
  Via poetry:
70
70
 
71
71
  ```bash
72
- $ poetry add pangea-sdk==5.2.0b2
72
+ $ poetry add pangea-sdk==5.4.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.2.0b2
44
+ $ pip3 install pangea-sdk==5.4.0b2
45
45
  ```
46
46
 
47
47
  Via poetry:
48
48
 
49
49
  ```bash
50
- $ poetry add pangea-sdk==5.2.0b2
50
+ $ poetry add pangea-sdk==5.4.0b2
51
51
  ```
52
52
 
53
53
  ## Usage
@@ -1,4 +1,4 @@
1
- __version__ = "5.3.0"
1
+ __version__ = "5.4.0beta2"
2
2
 
3
3
  from pangea.asyncio.request import PangeaRequestAsync
4
4
  from pangea.config import PangeaConfig
@@ -5,11 +5,12 @@ from __future__ import annotations
5
5
  import asyncio
6
6
  import json
7
7
  import time
8
- from typing import Any, Dict, List, Optional, Sequence, Tuple, Type, Union
8
+ from typing import Dict, List, Optional, Sequence, Tuple, Type, Union, cast
9
9
 
10
10
  import aiohttp
11
11
  from aiohttp import FormData
12
12
  from pydantic import BaseModel
13
+ from pydantic_core import to_jsonable_python
13
14
  from typing_extensions import Any, TypeVar
14
15
 
15
16
  import pangea.exceptions as pe
@@ -52,20 +53,27 @@ class PangeaRequestAsync(PangeaRequestBase):
52
53
  if isinstance(data, BaseModel):
53
54
  data = data.model_dump(exclude_none=True)
54
55
 
56
+ if isinstance(data, dict):
57
+ # Remove `None` values.
58
+ data = {k: v for k, v in data.items() if v is not None}
59
+
55
60
  if data is None:
56
61
  data = {}
57
62
 
63
+ # Normalize.
64
+ data = cast(dict[str, Any], to_jsonable_python(data))
65
+
58
66
  if url is None:
59
67
  url = self._url(endpoint)
60
68
 
61
69
  # Set config ID if available
62
- if self.config_id and data.get("config_id", None) is None: # type: ignore[union-attr]
63
- data["config_id"] = self.config_id # type: ignore[index]
70
+ if self.config_id and data.get("config_id", None) is None:
71
+ data["config_id"] = self.config_id
64
72
 
65
73
  self.logger.debug(
66
74
  json.dumps({"service": self.service, "action": "post", "url": url, "data": data}, default=default_encoder)
67
75
  )
68
- transfer_method = data.get("transfer_method", None) # type: ignore[union-attr]
76
+ transfer_method = data.get("transfer_method", None)
69
77
 
70
78
  if files and type(data) is dict and (transfer_method == TransferMethod.POST_URL.value):
71
79
  requests_response = await self._full_post_presigned_url(
@@ -1,9 +1,11 @@
1
+ from .ai_guard import AIGuardAsync
1
2
  from .audit import AuditAsync
2
3
  from .authn import AuthNAsync
3
4
  from .authz import AuthZAsync
4
5
  from .embargo import EmbargoAsync
5
6
  from .file_scan import FileScanAsync
6
7
  from .intel import DomainIntelAsync, FileIntelAsync, IpIntelAsync, UrlIntelAsync, UserIntelAsync
8
+ from .prompt_guard import PromptGuardAsync
7
9
  from .redact import RedactAsync
8
10
  from .sanitize import SanitizeAsync
9
11
  from .share import ShareAsync
@@ -0,0 +1,75 @@
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
+ )
@@ -0,0 +1,76 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ from pangea.asyncio.services.base import ServiceBaseAsync
6
+ from pangea.config import PangeaConfig
7
+ from pangea.services.prompt_guard import GuardResult, Message
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Iterable
11
+
12
+ from pangea.response import PangeaResponse
13
+
14
+
15
+ class PromptGuardAsync(ServiceBaseAsync):
16
+ """Prompt Guard service client.
17
+
18
+ Provides methods to interact with Pangea's Prompt Guard service.
19
+
20
+ Examples:
21
+ from pangea import PangeaConfig
22
+ from pangea.asyncio.services import PromptGuardAsync
23
+
24
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
25
+ prompt_guard = PromptGuardAsync(token="pangea_token", config=config)
26
+ """
27
+
28
+ service_name = "prompt-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
+ Prompt Guard service client.
35
+
36
+ Initializes a new Prompt 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 PromptGuardAsync
47
+
48
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
49
+ prompt_guard = PromptGuardAsync(token="pangea_token", config=config)
50
+ """
51
+
52
+ super().__init__(token, config, logger_name, config_id)
53
+
54
+ async def guard(
55
+ self, messages: Iterable[Message], *, analyzers: Iterable[str] | None = None
56
+ ) -> PangeaResponse[GuardResult]:
57
+ """
58
+ Guard (Beta)
59
+
60
+ Guard messages.
61
+
62
+ How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
63
+
64
+ OperationId: prompt_guard_post_v1beta_guard
65
+
66
+ Args:
67
+ messages: Messages.
68
+ analyzers: Specific analyzers to be used in the call.
69
+
70
+ Examples:
71
+ from pangea.asyncio.services.prompt_guard import Message
72
+
73
+ response = await prompt_guard.guard([Message(role="user", content="hello world")])
74
+ """
75
+
76
+ return await self.request.post("v1beta/guard", GuardResult, data={"messages": messages, "analyzers": analyzers})
@@ -97,7 +97,7 @@ class SanitizeAsync(ServiceBaseAsync):
97
97
  performed.
98
98
 
99
99
  Examples:
100
- with open("/path/to/file.pdf", "rb") as f:
100
+ with open("/path/to/file.txt", "rb") as f:
101
101
  response = await sanitize.sanitize(
102
102
  file=f,
103
103
  transfer_method=TransferMethod.POST_URL,
@@ -6,10 +6,11 @@ import copy
6
6
  import json
7
7
  import logging
8
8
  import time
9
- from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple, Type, Union
9
+ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple, Type, Union, cast
10
10
 
11
11
  import requests
12
12
  from pydantic import BaseModel
13
+ from pydantic_core import to_jsonable_python
13
14
  from requests.adapters import HTTPAdapter, Retry
14
15
  from requests_toolbelt import MultipartDecoder # type: ignore[import-untyped]
15
16
  from typing_extensions import TypeVar
@@ -229,9 +230,16 @@ class PangeaRequest(PangeaRequestBase):
229
230
  if isinstance(data, BaseModel):
230
231
  data = data.model_dump(exclude_none=True)
231
232
 
233
+ if isinstance(data, dict):
234
+ # Remove `None` values.
235
+ data = {k: v for k, v in data.items() if v is not None}
236
+
232
237
  if data is None:
233
238
  data = {}
234
239
 
240
+ # Normalize.
241
+ data = cast(dict[str, Any], to_jsonable_python(data))
242
+
235
243
  if url is None:
236
244
  url = self._url(endpoint)
237
245
 
@@ -1,9 +1,11 @@
1
+ from .ai_guard import AIGuard
1
2
  from .audit.audit import Audit
2
3
  from .authn.authn import AuthN
3
4
  from .authz import AuthZ
4
5
  from .embargo import Embargo
5
6
  from .file_scan import FileScan
6
7
  from .intel import DomainIntel, FileIntel, IpIntel, UrlIntel, UserIntel
8
+ from .prompt_guard import PromptGuard
7
9
  from .redact import Redact
8
10
  from .sanitize import Sanitize
9
11
  from .share.share import Share
@@ -0,0 +1,128 @@
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
+ )
@@ -0,0 +1,110 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Literal, Optional
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
+ if TYPE_CHECKING:
10
+ from collections.abc import Iterable
11
+
12
+
13
+ class Message(APIRequestModel):
14
+ role: str
15
+ content: str
16
+
17
+
18
+ class Classification(APIResponseModel):
19
+ category: str
20
+ """Classification category"""
21
+
22
+ label: str
23
+ """Classification label"""
24
+
25
+ confidence: float
26
+ """Confidence score for the classification"""
27
+
28
+
29
+ class GuardResult(PangeaResponseResult):
30
+ detected: bool
31
+ """Boolean response for if the prompt was considered malicious or not"""
32
+
33
+ type: Optional[Literal["direct", "indirect"]] = None
34
+ """Type of analysis, either direct or indirect"""
35
+
36
+ analyzer: Optional[str] = None
37
+ """Prompt Analyzers for identifying and rejecting properties of prompts"""
38
+
39
+ confidence: int
40
+ """Percent of confidence in the detection result, ranging from 0 to 100"""
41
+
42
+ info: Optional[str] = None
43
+ """Extra information about the detection result"""
44
+
45
+ classifications: list[Classification]
46
+ """List of classification results with labels and confidence scores"""
47
+
48
+
49
+ class PromptGuard(ServiceBase):
50
+ """Prompt Guard service client.
51
+
52
+ Provides methods to interact with Pangea's Prompt Guard service.
53
+
54
+ Examples:
55
+ from pangea import PangeaConfig
56
+ from pangea.services import PromptGuard
57
+
58
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
59
+ prompt_guard = PromptGuard(token="pangea_token", config=config)
60
+ """
61
+
62
+ service_name = "prompt-guard"
63
+
64
+ def __init__(
65
+ self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
66
+ ) -> None:
67
+ """
68
+ Prompt Guard service client.
69
+
70
+ Initializes a new Prompt Guard client.
71
+
72
+ Args:
73
+ token: Pangea API token.
74
+ config: Pangea service configuration.
75
+ logger_name: Logger name.
76
+ config_id: Configuration ID.
77
+
78
+ Examples:
79
+ from pangea import PangeaConfig
80
+ from pangea.services import PromptGuard
81
+
82
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
83
+ prompt_guard = PromptGuard(token="pangea_token", config=config)
84
+ """
85
+
86
+ super().__init__(token, config, logger_name, config_id)
87
+
88
+ def guard(
89
+ self, messages: Iterable[Message], *, analyzers: Iterable[str] | None = None
90
+ ) -> PangeaResponse[GuardResult]:
91
+ """
92
+ Guard (Beta)
93
+
94
+ Guard messages.
95
+
96
+ How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
97
+
98
+ OperationId: prompt_guard_post_v1beta_guard
99
+
100
+ Args:
101
+ messages: Prompt content and role array.
102
+ analyzers: Specific analyzers to be used in the call.
103
+
104
+ Examples:
105
+ from pangea.services.prompt_guard import Message
106
+
107
+ response = prompt_guard.guard([Message(role="user", content="hello world")])
108
+ """
109
+
110
+ return self.request.post("v1beta/guard", GuardResult, data={"messages": messages, "analyzers": analyzers})
@@ -46,12 +46,6 @@ class SanitizeContent(APIRequestModel):
46
46
  analysis engine results. Only works if redact is enabled.
47
47
  """
48
48
 
49
- remove_attachments: Optional[bool] = None
50
- """Remove file attachments (PDF only)."""
51
-
52
- remove_interactive: Optional[bool] = None
53
- """Remove interactive content (PDF only)."""
54
-
55
49
 
56
50
  class SanitizeShareOutput(APIRequestModel):
57
51
  enabled: Optional[bool] = None
@@ -144,14 +138,6 @@ class RedactData(PangeaResponseResult):
144
138
  """The scoring result of a set of rules."""
145
139
 
146
140
 
147
- class CDR(PangeaResponseResult):
148
- file_attachments_removed: Optional[int] = None
149
- """Number of file attachments removed."""
150
-
151
- interactive_contents_removed: Optional[int] = None
152
- """Number of interactive content items removed."""
153
-
154
-
155
141
  class SanitizeData(PangeaResponseResult):
156
142
  defang: Optional[DefangData] = None
157
143
  """Defang."""
@@ -162,9 +148,6 @@ class SanitizeData(PangeaResponseResult):
162
148
  malicious_file: Optional[bool] = None
163
149
  """If the file scanned was malicious."""
164
150
 
165
- cdr: Optional[CDR] = None
166
- """Content Disarm and Reconstruction."""
167
-
168
151
 
169
152
  class SanitizeResult(PangeaResponseResult):
170
153
  dest_url: Optional[str] = None
@@ -265,7 +248,7 @@ class Sanitize(ServiceBase):
265
248
  performed.
266
249
 
267
250
  Examples:
268
- with open("/path/to/file.pdf", "rb") as f:
251
+ with open("/path/to/file.txt", "rb") as f:
269
252
  response = sanitize.sanitize(
270
253
  file=f,
271
254
  transfer_method=TransferMethod.POST_URL,
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pangea-sdk"
3
- version = "5.3.0"
3
+ version = "5.4.0beta2"
4
4
  description = "Pangea API SDK"
5
5
  authors = [
6
6
  {name = "Glenn Gallien", email = "glenn.gallien@pangea.cloud"}
@@ -71,5 +71,5 @@ show_column_numbers = true
71
71
  warn_unused_ignores = true
72
72
 
73
73
  [build-system]
74
- requires = ["poetry-core>=2.0.0"]
74
+ requires = ["poetry-core>=2.0.1"]
75
75
  build-backend = "poetry.core.masonry.api"
File without changes
File without changes
File without changes