Skip to content

Commit 6f8620d

Browse files
committed
Add Prompt Guard config APIs
1 parent 583c901 commit 6f8620d

File tree

8 files changed

+1657
-16
lines changed

8 files changed

+1657
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- AI Guard: config APIs.
13+
- Prompt Guard: config APIs.
1314

1415
## 6.1.1 - 2025-05-12
1516

packages/pangea-sdk/pangea/asyncio/services/prompt_guard.py

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING
3+
from collections.abc import Mapping
4+
from typing import TYPE_CHECKING, Literal
45

56
from pangea.asyncio.services.base import ServiceBaseAsync
67
from pangea.config import PangeaConfig
7-
from pangea.services.prompt_guard import GuardResult, Message
8+
from pangea.response import PangeaResponseResult
9+
from pangea.services.prompt_guard import (
10+
AuditDataActivityConfig,
11+
GuardResult,
12+
Message,
13+
ServiceConfigFilter,
14+
ServiceConfigsPage,
15+
)
816

917
if TYPE_CHECKING:
1018
from collections.abc import Iterable
@@ -82,3 +90,105 @@ async def guard(
8290
GuardResult,
8391
data={"messages": messages, "analyzers": analyzers, "classify": classify},
8492
)
93+
94+
async def get_service_config(
95+
self,
96+
*,
97+
id: str | None = None,
98+
version: str | None = None,
99+
analyzers: Mapping[str, bool] | None = None,
100+
malicious_detection_threshold: float | None = None,
101+
benign_detection_threshold: float | None = None,
102+
audit_data_activity: AuditDataActivityConfig | None = None,
103+
) -> PangeaResponse[PangeaResponseResult]:
104+
"""
105+
OperationId: prompt_guard_post_v1beta_config
106+
"""
107+
return await self.request.post(
108+
"v1beta/config",
109+
data={
110+
"id": id,
111+
"version": version,
112+
"analyzers": analyzers,
113+
"malicious_detection_threshold": malicious_detection_threshold,
114+
"benign_detection_threshold": benign_detection_threshold,
115+
"audit_data_activity": audit_data_activity,
116+
},
117+
result_class=PangeaResponseResult,
118+
)
119+
120+
async def create_service_config(
121+
self,
122+
*,
123+
id: str | None = None,
124+
version: str | None = None,
125+
analyzers: Mapping[str, bool] | None = None,
126+
malicious_detection_threshold: float | None = None,
127+
benign_detection_threshold: float | None = None,
128+
audit_data_activity: AuditDataActivityConfig | None = None,
129+
) -> PangeaResponse[PangeaResponseResult]:
130+
"""
131+
OperationId: prompt_guard_post_v1beta_config_create
132+
"""
133+
return await self.request.post(
134+
"v1beta/config/create",
135+
data={
136+
"id": id,
137+
"version": version,
138+
"analyzers": analyzers,
139+
"malicious_detection_threshold": malicious_detection_threshold,
140+
"benign_detection_threshold": benign_detection_threshold,
141+
"audit_data_activity": audit_data_activity,
142+
},
143+
result_class=PangeaResponseResult,
144+
)
145+
146+
async def update_service_config(
147+
self,
148+
*,
149+
id: str | None = None,
150+
version: str | None = None,
151+
analyzers: Mapping[str, bool] | None = None,
152+
malicious_detection_threshold: float | None = None,
153+
benign_detection_threshold: float | None = None,
154+
audit_data_activity: AuditDataActivityConfig | None = None,
155+
) -> PangeaResponse[PangeaResponseResult]:
156+
"""
157+
OperationId: prompt_guard_post_v1beta_config_update
158+
"""
159+
return await self.request.post(
160+
"v1beta/config/update",
161+
data={
162+
"id": id,
163+
"version": version,
164+
"analyzers": analyzers,
165+
"malicious_detection_threshold": malicious_detection_threshold,
166+
"benign_detection_threshold": benign_detection_threshold,
167+
"audit_data_activity": audit_data_activity,
168+
},
169+
result_class=PangeaResponseResult,
170+
)
171+
172+
async def delete_service_config(self, id: str) -> PangeaResponse[PangeaResponseResult]:
173+
"""
174+
OperationId: prompt_guard_post_v1beta_config_delete
175+
"""
176+
return await self.request.post("v1beta/config/delete", data={"id": id}, result_class=PangeaResponseResult)
177+
178+
async def list_service_configs(
179+
self,
180+
*,
181+
filter: ServiceConfigFilter | None = None,
182+
last: str | None = None,
183+
order: Literal["asc", "desc"] | None = None,
184+
order_by: Literal["id", "created_at", "updated_at"] | None = None,
185+
size: int | None = None,
186+
) -> PangeaResponse[ServiceConfigsPage]:
187+
"""
188+
OperationId: prompt_guard_post_v1beta_config_list
189+
"""
190+
return await self.request.post(
191+
"v1beta/config/list",
192+
data={"filter": filter, "last": last, "order": order, "order_by": order_by, "size": size},
193+
result_class=ServiceConfigsPage,
194+
)

packages/pangea-sdk/pangea/services/ai_guard.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from __future__ import annotations
22

33
from collections.abc import Mapping
4-
from datetime import datetime
54
from typing import Annotated, Generic, Literal, Optional, Union, overload
65

76
from pydantic import BaseModel, ConfigDict, Field, RootModel
87
from typing_extensions import TypeVar
98

109
from pangea.config import PangeaConfig
11-
from pangea.response import APIRequestModel, APIResponseModel, PangeaResponse, PangeaResponseResult
10+
from pangea.response import APIRequestModel, APIResponseModel, PangeaDateTime, PangeaResponse, PangeaResponseResult
1211
from pangea.services.base import ServiceBase
1312

1413
# This is named "prompt injection" in the API spec even though it is also used
@@ -648,43 +647,43 @@ class ServiceConfigFilter(BaseModel):
648647
"""
649648
Only records where id equals one of the provided substrings.
650649
"""
651-
created_at: Optional[datetime] = None
650+
created_at: Optional[PangeaDateTime] = None
652651
"""
653652
Only records where created_at equals this value.
654653
"""
655-
created_at__gt: Optional[datetime] = None
654+
created_at__gt: Optional[PangeaDateTime] = None
656655
"""
657656
Only records where created_at is greater than this value.
658657
"""
659-
created_at__gte: Optional[datetime] = None
658+
created_at__gte: Optional[PangeaDateTime] = None
660659
"""
661660
Only records where created_at is greater than or equal to this value.
662661
"""
663-
created_at__lt: Optional[datetime] = None
662+
created_at__lt: Optional[PangeaDateTime] = None
664663
"""
665664
Only records where created_at is less than this value.
666665
"""
667-
created_at__lte: Optional[datetime] = None
666+
created_at__lte: Optional[PangeaDateTime] = None
668667
"""
669668
Only records where created_at is less than or equal to this value.
670669
"""
671-
updated_at: Optional[datetime] = None
670+
updated_at: Optional[PangeaDateTime] = None
672671
"""
673672
Only records where updated_at equals this value.
674673
"""
675-
updated_at__gt: Optional[datetime] = None
674+
updated_at__gt: Optional[PangeaDateTime] = None
676675
"""
677676
Only records where updated_at is greater than this value.
678677
"""
679-
updated_at__gte: Optional[datetime] = None
678+
updated_at__gte: Optional[PangeaDateTime] = None
680679
"""
681680
Only records where updated_at is greater than or equal to this value.
682681
"""
683-
updated_at__lt: Optional[datetime] = None
682+
updated_at__lt: Optional[PangeaDateTime] = None
684683
"""
685684
Only records where updated_at is less than this value.
686685
"""
687-
updated_at__lte: Optional[datetime] = None
686+
updated_at__lte: Optional[PangeaDateTime] = None
688687
"""
689688
Only records where updated_at is less than or equal to this value.
690689
"""

0 commit comments

Comments
 (0)