enkryptai-sdk 1.0.20__py3-none-any.whl → 1.0.23__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.
- enkryptai_sdk/dto/coc.py +8 -0
- enkryptai_sdk/dto/datasets.py +2 -0
- enkryptai_sdk/dto/deployments.py +14 -2
- enkryptai_sdk/dto/guardrails.py +125 -0
- enkryptai_sdk/dto/models.py +2 -0
- enkryptai_sdk/dto/red_team.py +47 -0
- enkryptai_sdk/guardrails.py +91 -0
- enkryptai_sdk/red_team.py +28 -0
- enkryptai_sdk-1.0.23.dist-info/METADATA +42 -0
- {enkryptai_sdk-1.0.20.dist-info → enkryptai_sdk-1.0.23.dist-info}/RECORD +13 -13
- enkryptai_sdk-1.0.20.dist-info/METADATA +0 -1994
- {enkryptai_sdk-1.0.20.dist-info → enkryptai_sdk-1.0.23.dist-info}/WHEEL +0 -0
- {enkryptai_sdk-1.0.20.dist-info → enkryptai_sdk-1.0.23.dist-info}/licenses/LICENSE +0 -0
- {enkryptai_sdk-1.0.20.dist-info → enkryptai_sdk-1.0.23.dist-info}/top_level.txt +0 -0
enkryptai_sdk/dto/coc.py
CHANGED
|
@@ -7,6 +7,8 @@ from typing import List, Dict, Any, Set, Optional, BinaryIO
|
|
|
7
7
|
@dataclass
|
|
8
8
|
class CoCPolicyData(BaseDTO):
|
|
9
9
|
created_at: str
|
|
10
|
+
created_by: str
|
|
11
|
+
updated_by: str
|
|
10
12
|
name: str
|
|
11
13
|
updated_at: str
|
|
12
14
|
policy_id: int
|
|
@@ -20,6 +22,8 @@ class CoCPolicyData(BaseDTO):
|
|
|
20
22
|
def from_dict(cls, data: Dict[str, Any]) -> "CoCPolicyData":
|
|
21
23
|
return cls(
|
|
22
24
|
created_at=data.get("created_at", ""),
|
|
25
|
+
created_by=data.get("created_by", ""),
|
|
26
|
+
updated_by=data.get("updated_by", ""),
|
|
23
27
|
name=data.get("name", ""),
|
|
24
28
|
updated_at=data.get("updated_at", ""),
|
|
25
29
|
policy_id=data.get("policy_id", 0),
|
|
@@ -32,6 +36,8 @@ class CoCPolicyData(BaseDTO):
|
|
|
32
36
|
def to_dict(self) -> Dict[str, Any]:
|
|
33
37
|
result = {
|
|
34
38
|
"created_at": self.created_at,
|
|
39
|
+
"created_by": self.created_by,
|
|
40
|
+
"updated_by": self.updated_by,
|
|
35
41
|
"name": self.name,
|
|
36
42
|
"updated_at": self.updated_at,
|
|
37
43
|
"policy_id": self.policy_id,
|
|
@@ -65,6 +71,8 @@ class CoCPolicyData(BaseDTO):
|
|
|
65
71
|
f"Policy Name: {self.name}\n"
|
|
66
72
|
f"Created At: {self.created_at}\n"
|
|
67
73
|
f"Updated At: {self.updated_at}\n"
|
|
74
|
+
f"Created By: {self.created_by}\n"
|
|
75
|
+
f"Updated By: {self.updated_by}\n"
|
|
68
76
|
f"Policy ID: {self.policy_id}\n"
|
|
69
77
|
f"total_rules: {self.total_rules}\n"
|
|
70
78
|
)
|
enkryptai_sdk/dto/datasets.py
CHANGED
|
@@ -92,6 +92,7 @@ class DatasetContent(BaseDTO):
|
|
|
92
92
|
class DatasetTaskData(BaseDTO):
|
|
93
93
|
dataset_name: str
|
|
94
94
|
created_at: str
|
|
95
|
+
created_by: str
|
|
95
96
|
started_at: str
|
|
96
97
|
status: str
|
|
97
98
|
system_description: str
|
|
@@ -110,6 +111,7 @@ class DatasetTaskData(BaseDTO):
|
|
|
110
111
|
return cls(
|
|
111
112
|
dataset_name=data.get("dataset_name", ""),
|
|
112
113
|
created_at=data.get("created_at", ""),
|
|
114
|
+
created_by=data.get("created_by", ""),
|
|
113
115
|
started_at=data.get("started_at", ""),
|
|
114
116
|
status=data.get("status", ""),
|
|
115
117
|
system_description=data.get("system_description", ""),
|
enkryptai_sdk/dto/deployments.py
CHANGED
|
@@ -182,6 +182,8 @@ class GetDeploymentResponse(BaseDTO):
|
|
|
182
182
|
output_guardrails_policy: OutputGuardrailsPolicy
|
|
183
183
|
created_at: str
|
|
184
184
|
updated_at: str
|
|
185
|
+
created_by: str
|
|
186
|
+
updated_by: str
|
|
185
187
|
deployment_id: int
|
|
186
188
|
|
|
187
189
|
@classmethod
|
|
@@ -197,7 +199,9 @@ class GetDeploymentResponse(BaseDTO):
|
|
|
197
199
|
output_guardrails_policy=OutputGuardrailsPolicy.from_dict(output_policy_data),
|
|
198
200
|
updated_at=data.get("updated_at", ""),
|
|
199
201
|
deployment_id=data.get("deployment_id", 0),
|
|
200
|
-
created_at=data.get("created_at", "")
|
|
202
|
+
created_at=data.get("created_at", ""),
|
|
203
|
+
created_by=data.get("created_by", ""),
|
|
204
|
+
updated_by=data.get("updated_by", "")
|
|
201
205
|
)
|
|
202
206
|
|
|
203
207
|
def to_dict(self) -> Dict[str, Any]:
|
|
@@ -209,7 +213,9 @@ class GetDeploymentResponse(BaseDTO):
|
|
|
209
213
|
"output_guardrails_policy": self.output_guardrails_policy.to_dict(),
|
|
210
214
|
"updated_at": self.updated_at,
|
|
211
215
|
"deployment_id": self.deployment_id,
|
|
212
|
-
"created_at": self.created_at
|
|
216
|
+
"created_at": self.created_at,
|
|
217
|
+
"created_by": self.created_by,
|
|
218
|
+
"updated_by": self.updated_by
|
|
213
219
|
}
|
|
214
220
|
|
|
215
221
|
|
|
@@ -300,6 +306,8 @@ class DeploymentSummary(BaseDTO):
|
|
|
300
306
|
name: str
|
|
301
307
|
created_at: str
|
|
302
308
|
updated_at: str
|
|
309
|
+
created_by: str
|
|
310
|
+
updated_by: str
|
|
303
311
|
model_saved_name: str
|
|
304
312
|
model_version: str
|
|
305
313
|
project_name: str
|
|
@@ -311,6 +319,8 @@ class DeploymentSummary(BaseDTO):
|
|
|
311
319
|
name=data.get("name", ""),
|
|
312
320
|
created_at=data.get("created_at", ""),
|
|
313
321
|
updated_at=data.get("updated_at", ""),
|
|
322
|
+
created_by=data.get("created_by", ""),
|
|
323
|
+
updated_by=data.get("updated_by", ""),
|
|
314
324
|
model_saved_name=data.get("model_saved_name", ""),
|
|
315
325
|
model_version=data.get("model_version", ""),
|
|
316
326
|
project_name=data.get("project_name", "")
|
|
@@ -322,6 +332,8 @@ class DeploymentSummary(BaseDTO):
|
|
|
322
332
|
"name": self.name,
|
|
323
333
|
"created_at": self.created_at,
|
|
324
334
|
"updated_at": self.updated_at,
|
|
335
|
+
"created_by": self.created_by,
|
|
336
|
+
"updated_by": self.updated_by,
|
|
325
337
|
"model_saved_name": self.model_saved_name,
|
|
326
338
|
"model_version": self.model_version,
|
|
327
339
|
"project_name": self.project_name
|
enkryptai_sdk/dto/guardrails.py
CHANGED
|
@@ -1365,6 +1365,8 @@ class GuardrailsPolicyData(BaseDTO):
|
|
|
1365
1365
|
created_at: str
|
|
1366
1366
|
name: str
|
|
1367
1367
|
updated_at: str
|
|
1368
|
+
created_by: str
|
|
1369
|
+
updated_by: str
|
|
1368
1370
|
description: str
|
|
1369
1371
|
policy_id: int
|
|
1370
1372
|
project_name: str = ""
|
|
@@ -1379,6 +1381,8 @@ class GuardrailsPolicyData(BaseDTO):
|
|
|
1379
1381
|
created_at=data.get("created_at", ""),
|
|
1380
1382
|
name=data.get("name", ""),
|
|
1381
1383
|
updated_at=data.get("updated_at", ""),
|
|
1384
|
+
created_by=data.get("created_by", ""),
|
|
1385
|
+
updated_by=data.get("updated_by", ""),
|
|
1382
1386
|
description=data.get("description", ""),
|
|
1383
1387
|
policy_id=data.get("policy_id", 0),
|
|
1384
1388
|
project_name=data.get("project_name", ""),
|
|
@@ -1390,6 +1394,8 @@ class GuardrailsPolicyData(BaseDTO):
|
|
|
1390
1394
|
"created_at": self.created_at,
|
|
1391
1395
|
"name": self.name,
|
|
1392
1396
|
"updated_at": self.updated_at,
|
|
1397
|
+
"created_by": self.created_by,
|
|
1398
|
+
"updated_by": self.updated_by,
|
|
1393
1399
|
"description": self.description,
|
|
1394
1400
|
"policy_id": self.policy_id,
|
|
1395
1401
|
"project_name": self.project_name,
|
|
@@ -1474,6 +1480,8 @@ class GuardrailsPolicyListItem(BaseDTO):
|
|
|
1474
1480
|
description: str
|
|
1475
1481
|
created_at: str
|
|
1476
1482
|
updated_at: str
|
|
1483
|
+
created_by: str
|
|
1484
|
+
updated_by: str
|
|
1477
1485
|
project_name: str = "default"
|
|
1478
1486
|
_extra_fields: Dict[str, Any] = field(default_factory=dict)
|
|
1479
1487
|
|
|
@@ -1485,6 +1493,8 @@ class GuardrailsPolicyListItem(BaseDTO):
|
|
|
1485
1493
|
description=data.get("description", ""),
|
|
1486
1494
|
created_at=data.get("created_at", ""),
|
|
1487
1495
|
updated_at=data.get("updated_at", ""),
|
|
1496
|
+
created_by=data.get("created_by", ""),
|
|
1497
|
+
updated_by=data.get("updated_by", ""),
|
|
1488
1498
|
project_name=data.get("project_name", "default")
|
|
1489
1499
|
)
|
|
1490
1500
|
|
|
@@ -1495,6 +1505,8 @@ class GuardrailsPolicyListItem(BaseDTO):
|
|
|
1495
1505
|
"description": self.description,
|
|
1496
1506
|
"created_at": self.created_at,
|
|
1497
1507
|
"updated_at": self.updated_at,
|
|
1508
|
+
"created_by": self.created_by,
|
|
1509
|
+
"updated_by": self.updated_by,
|
|
1498
1510
|
"project_name": self.project_name
|
|
1499
1511
|
}
|
|
1500
1512
|
result.update(self._extra_fields)
|
|
@@ -1625,4 +1637,117 @@ class GuardrailsPolicyAtomizerResponse(BaseDTO):
|
|
|
1625
1637
|
f"Total Rules: {self.total_rules}\n"
|
|
1626
1638
|
f"Message: {self.message}"
|
|
1627
1639
|
)
|
|
1640
|
+
|
|
1641
|
+
|
|
1642
|
+
@dataclass
|
|
1643
|
+
class GuardrailsViolation(BaseDTO):
|
|
1644
|
+
unsafe_content: str
|
|
1645
|
+
chunk_type: str
|
|
1646
|
+
triggered_detectors: List[str]
|
|
1647
|
+
guardrails_result: Dict[str, Any]
|
|
1648
|
+
_extra_fields: Dict[str, Any] = field(default_factory=dict)
|
|
1649
|
+
|
|
1650
|
+
@classmethod
|
|
1651
|
+
def from_dict(cls, data: Dict[str, Any]) -> "GuardrailsViolation":
|
|
1652
|
+
return cls(
|
|
1653
|
+
unsafe_content=data.get("unsafe_content", ""),
|
|
1654
|
+
chunk_type=data.get("chunk_type", ""),
|
|
1655
|
+
triggered_detectors=data.get("triggered_detectors", []),
|
|
1656
|
+
guardrails_result=data.get("guardrails_result", {})
|
|
1657
|
+
)
|
|
1628
1658
|
|
|
1659
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
1660
|
+
result = {
|
|
1661
|
+
"unsafe_content": self.unsafe_content,
|
|
1662
|
+
"chunk_type": self.chunk_type,
|
|
1663
|
+
"triggered_detectors": self.triggered_detectors,
|
|
1664
|
+
"guardrails_result": self.guardrails_result
|
|
1665
|
+
}
|
|
1666
|
+
result.update(self._extra_fields)
|
|
1667
|
+
return result
|
|
1668
|
+
|
|
1669
|
+
|
|
1670
|
+
@dataclass
|
|
1671
|
+
class GuardrailsScanUrlResponse(BaseDTO):
|
|
1672
|
+
url: str
|
|
1673
|
+
violations: List[GuardrailsViolation]
|
|
1674
|
+
combined_highlight_url: str
|
|
1675
|
+
_extra_fields: Dict[str, Any] = field(default_factory=dict)
|
|
1676
|
+
|
|
1677
|
+
@classmethod
|
|
1678
|
+
def from_dict(cls, data: Dict[str, Any]) -> "GuardrailsScanUrlResponse":
|
|
1679
|
+
violations_data = data.get("violations", [])
|
|
1680
|
+
violations = [GuardrailsViolation.from_dict(violation) for violation in violations_data]
|
|
1681
|
+
|
|
1682
|
+
return cls(
|
|
1683
|
+
url=data.get("url", ""),
|
|
1684
|
+
violations=violations,
|
|
1685
|
+
combined_highlight_url=data.get("combined_highlight_url", "")
|
|
1686
|
+
)
|
|
1687
|
+
|
|
1688
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
1689
|
+
result = {
|
|
1690
|
+
"url": self.url,
|
|
1691
|
+
"violations": [violation.to_dict() for violation in self.violations],
|
|
1692
|
+
"combined_highlight_url": self.combined_highlight_url
|
|
1693
|
+
}
|
|
1694
|
+
result.update(self._extra_fields)
|
|
1695
|
+
return result
|
|
1696
|
+
|
|
1697
|
+
def has_violations(self) -> bool:
|
|
1698
|
+
"""
|
|
1699
|
+
Check if any detectors found violations in the URL content.
|
|
1700
|
+
|
|
1701
|
+
Returns:
|
|
1702
|
+
bool: True if any violations were detected, False otherwise
|
|
1703
|
+
"""
|
|
1704
|
+
return len(self.violations) > 0
|
|
1705
|
+
|
|
1706
|
+
def get_violations(self) -> List[str]:
|
|
1707
|
+
"""
|
|
1708
|
+
Get a list of detector names that found violations.
|
|
1709
|
+
|
|
1710
|
+
Returns:
|
|
1711
|
+
List[str]: Names of detectors that reported violations
|
|
1712
|
+
"""
|
|
1713
|
+
triggered_detectors = []
|
|
1714
|
+
for violation in self.violations:
|
|
1715
|
+
triggered_detectors.extend(violation.triggered_detectors)
|
|
1716
|
+
# Remove duplicates while preserving order
|
|
1717
|
+
return list(dict.fromkeys(triggered_detectors))
|
|
1718
|
+
|
|
1719
|
+
def is_safe(self) -> bool:
|
|
1720
|
+
"""
|
|
1721
|
+
Check if the URL content is safe (no violations detected).
|
|
1722
|
+
|
|
1723
|
+
Returns:
|
|
1724
|
+
bool: True if no violations were detected, False otherwise
|
|
1725
|
+
"""
|
|
1726
|
+
return not self.has_violations()
|
|
1727
|
+
|
|
1728
|
+
def is_attack(self) -> bool:
|
|
1729
|
+
"""
|
|
1730
|
+
Check if the URL content is attacked (violations detected).
|
|
1731
|
+
|
|
1732
|
+
Returns:
|
|
1733
|
+
bool: True if violations were detected, False otherwise
|
|
1734
|
+
"""
|
|
1735
|
+
return self.has_violations()
|
|
1736
|
+
|
|
1737
|
+
def __str__(self) -> str:
|
|
1738
|
+
"""
|
|
1739
|
+
String representation of the response.
|
|
1740
|
+
|
|
1741
|
+
Returns:
|
|
1742
|
+
str: A formatted string showing URL, violations and status
|
|
1743
|
+
"""
|
|
1744
|
+
violations = self.get_violations()
|
|
1745
|
+
status = "UNSAFE" if violations else "SAFE"
|
|
1746
|
+
|
|
1747
|
+
if violations:
|
|
1748
|
+
violation_str = f"Violations detected: {', '.join(violations)}"
|
|
1749
|
+
else:
|
|
1750
|
+
violation_str = "No violations detected"
|
|
1751
|
+
|
|
1752
|
+
return f"URL Scan Result for {self.url}\nStatus: {status}\n{violation_str}"
|
|
1753
|
+
|
enkryptai_sdk/dto/models.py
CHANGED
|
@@ -268,6 +268,8 @@ class ModelConfigDetails(BaseDTO):
|
|
|
268
268
|
class ModelConfig(BaseDTO):
|
|
269
269
|
created_at: str = None
|
|
270
270
|
updated_at: str = None
|
|
271
|
+
created_by: str = None
|
|
272
|
+
updated_by: str = None
|
|
271
273
|
model_id: str = None
|
|
272
274
|
model_saved_name: str = None
|
|
273
275
|
model_version: str = None
|
enkryptai_sdk/dto/red_team.py
CHANGED
|
@@ -88,6 +88,7 @@ class RedTeamTaskDetailsModelConfig(BaseDTO):
|
|
|
88
88
|
@dataclass
|
|
89
89
|
class RedTeamTaskDetails(BaseDTO):
|
|
90
90
|
created_at: Optional[str] = None
|
|
91
|
+
created_by: Optional[str] = None
|
|
91
92
|
model_saved_name: Optional[str] = None
|
|
92
93
|
model_name: Optional[str] = None
|
|
93
94
|
status: Optional[str] = None
|
|
@@ -101,6 +102,7 @@ class RedTeamTaskDetails(BaseDTO):
|
|
|
101
102
|
# print(f"RedTeamTaskDetails data: {data}")
|
|
102
103
|
return cls(
|
|
103
104
|
created_at=data.get("created_at"),
|
|
105
|
+
created_by=data.get("created_by"),
|
|
104
106
|
model_saved_name=data.get("model_saved_name"),
|
|
105
107
|
model_name=data.get("model_name"),
|
|
106
108
|
status=data.get("status"),
|
|
@@ -112,6 +114,7 @@ class RedTeamTaskDetails(BaseDTO):
|
|
|
112
114
|
def to_dict(self) -> Dict:
|
|
113
115
|
return {
|
|
114
116
|
"created_at": self.created_at,
|
|
117
|
+
"created_by": self.created_by,
|
|
115
118
|
"model_saved_name": self.model_saved_name,
|
|
116
119
|
"model_name": self.model_name,
|
|
117
120
|
"status": self.status,
|
|
@@ -800,6 +803,50 @@ class RedTeamRiskMitigationSystemPromptResponse(BaseDTO):
|
|
|
800
803
|
"message": self.message,
|
|
801
804
|
}
|
|
802
805
|
|
|
806
|
+
@dataclass
|
|
807
|
+
class RedTeamKeyFinding(BaseDTO):
|
|
808
|
+
text: str
|
|
809
|
+
_extra_fields: Dict[str, Any] = field(default_factory=dict)
|
|
810
|
+
|
|
811
|
+
@classmethod
|
|
812
|
+
def from_dict(cls, data: Dict[str, Any]) -> "RedTeamKeyFinding":
|
|
813
|
+
return cls(
|
|
814
|
+
text=data.get("text", "")
|
|
815
|
+
)
|
|
816
|
+
|
|
817
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
818
|
+
result = {
|
|
819
|
+
"text": self.text
|
|
820
|
+
}
|
|
821
|
+
result.update(self._extra_fields)
|
|
822
|
+
return result
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
@dataclass
|
|
826
|
+
class RedTeamFindingsResponse(BaseDTO):
|
|
827
|
+
key_findings: List[RedTeamKeyFinding] = field(default_factory=list)
|
|
828
|
+
message: str = ""
|
|
829
|
+
_extra_fields: Dict[str, Any] = field(default_factory=dict)
|
|
830
|
+
|
|
831
|
+
@classmethod
|
|
832
|
+
def from_dict(cls, data: Dict[str, Any]) -> "RedTeamFindingsResponse":
|
|
833
|
+
key_findings_data = data.get("key_findings", [])
|
|
834
|
+
key_findings = [RedTeamKeyFinding.from_dict(finding) for finding in key_findings_data]
|
|
835
|
+
|
|
836
|
+
return cls(
|
|
837
|
+
key_findings=key_findings,
|
|
838
|
+
message=data.get("message", "")
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
842
|
+
result = {
|
|
843
|
+
"key_findings": [finding.to_dict() for finding in self.key_findings],
|
|
844
|
+
"message": self.message
|
|
845
|
+
}
|
|
846
|
+
result.update(self._extra_fields)
|
|
847
|
+
return result
|
|
848
|
+
|
|
849
|
+
|
|
803
850
|
|
|
804
851
|
# Default configurations
|
|
805
852
|
DEFAULT_REDTEAM_CONFIG = RedTeamConfig()
|
enkryptai_sdk/guardrails.py
CHANGED
|
@@ -31,6 +31,7 @@ from .dto import (
|
|
|
31
31
|
GuardrailsListPoliciesResponse,
|
|
32
32
|
GuardrailsPolicyAtomizerRequest,
|
|
33
33
|
GuardrailsPolicyAtomizerResponse,
|
|
34
|
+
GuardrailsScanUrlResponse
|
|
34
35
|
)
|
|
35
36
|
|
|
36
37
|
# ---------------------------------------
|
|
@@ -195,6 +196,28 @@ class GuardrailsClient(BaseClient):
|
|
|
195
196
|
return GuardrailsBatchDetectResponse.from_dict(response)
|
|
196
197
|
except Exception as e:
|
|
197
198
|
raise GuardrailsClientError(str(e))
|
|
199
|
+
|
|
200
|
+
def policy_batch_detect(self, policy_name, texts):
|
|
201
|
+
"""
|
|
202
|
+
Apply a specific policy to detect and filter content in multiple texts.
|
|
203
|
+
|
|
204
|
+
Parameters:
|
|
205
|
+
- policy_name (str): Name of the policy to apply
|
|
206
|
+
- texts (list): A list of texts to analyze
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
- GuardrailsBatchDetectResponse: Response from the API containing batch detection results
|
|
210
|
+
"""
|
|
211
|
+
headers = {"X-Enkrypt-Policy": policy_name}
|
|
212
|
+
payload = {"texts": texts}
|
|
213
|
+
|
|
214
|
+
try:
|
|
215
|
+
response = self._request("POST", "/guardrails/policy/batch/detect", headers=headers, json=payload)
|
|
216
|
+
if isinstance(response, dict) and response.get("error"):
|
|
217
|
+
raise GuardrailsClientError(f"API Error: {str(response)}")
|
|
218
|
+
return GuardrailsBatchDetectResponse.from_dict(response)
|
|
219
|
+
except Exception as e:
|
|
220
|
+
raise GuardrailsClientError(str(e))
|
|
198
221
|
|
|
199
222
|
def pii(self, text, mode="request", key="null", entities=None):
|
|
200
223
|
"""
|
|
@@ -267,6 +290,74 @@ class GuardrailsClient(BaseClient):
|
|
|
267
290
|
except Exception as e:
|
|
268
291
|
raise GuardrailsClientError(str(e))
|
|
269
292
|
|
|
293
|
+
def scan_url(self, url, config=None):
|
|
294
|
+
"""
|
|
295
|
+
Scan a URL for security threats including injection attacks and policy violations.
|
|
296
|
+
|
|
297
|
+
Parameters:
|
|
298
|
+
- url (str): The URL to scan and analyze.
|
|
299
|
+
- config (dict or GuardrailsConfig, optional): A configuration for detectors.
|
|
300
|
+
If a GuardrailsConfig instance is provided, its underlying dictionary will be used.
|
|
301
|
+
If not provided, defaults to injection attack and policy violation detection.
|
|
302
|
+
|
|
303
|
+
Returns:
|
|
304
|
+
- Response from the API.
|
|
305
|
+
"""
|
|
306
|
+
# Use default config if none provided
|
|
307
|
+
if config is None:
|
|
308
|
+
config = {
|
|
309
|
+
"injection_attack": {
|
|
310
|
+
"enabled": True
|
|
311
|
+
},
|
|
312
|
+
"policy_violation": {
|
|
313
|
+
"enabled": True,
|
|
314
|
+
"policy_text": "Detect any malicious text or injection attacks",
|
|
315
|
+
"need_explanation": True
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
# Allow passing in either a dict or a GuardrailsConfig or GuardrailDetectors instance
|
|
320
|
+
if hasattr(config, "as_dict"):
|
|
321
|
+
config = config.as_dict()
|
|
322
|
+
if hasattr(config, "to_dict"):
|
|
323
|
+
config = config.to_dict()
|
|
324
|
+
|
|
325
|
+
payload = {
|
|
326
|
+
"url": url,
|
|
327
|
+
"detectors": config
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
try:
|
|
331
|
+
response = self._request("POST", "/guardrails/scan-url", json=payload)
|
|
332
|
+
if response.get("error"):
|
|
333
|
+
raise GuardrailsClientError(f"API Error: {str(response)}")
|
|
334
|
+
return GuardrailsScanUrlResponse.from_dict(response)
|
|
335
|
+
except Exception as e:
|
|
336
|
+
raise GuardrailsClientError(str(e))
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def policy_scan_url(self, policy_name, url):
|
|
340
|
+
"""
|
|
341
|
+
Apply a specific policy to scan a URL for security threats.
|
|
342
|
+
|
|
343
|
+
Parameters:
|
|
344
|
+
- policy_name (str): Name of the policy to apply
|
|
345
|
+
- url (str): The URL to scan and analyze
|
|
346
|
+
|
|
347
|
+
Returns:
|
|
348
|
+
- GuardrailsScanUrlResponse: Response from the API containing scan results
|
|
349
|
+
"""
|
|
350
|
+
headers = {"X-Enkrypt-Policy": policy_name}
|
|
351
|
+
payload = {"url": url}
|
|
352
|
+
|
|
353
|
+
try:
|
|
354
|
+
response = self._request("POST", "/guardrails/policy/scan-url", headers=headers, json=payload)
|
|
355
|
+
if response.get("error"):
|
|
356
|
+
raise GuardrailsClientError(f"API Error: {str(response)}")
|
|
357
|
+
return GuardrailsScanUrlResponse.from_dict(response)
|
|
358
|
+
except Exception as e:
|
|
359
|
+
raise GuardrailsClientError(str(e))
|
|
360
|
+
|
|
270
361
|
# ----------------------------
|
|
271
362
|
# Guardrails Policy Endpoints
|
|
272
363
|
# ----------------------------
|
enkryptai_sdk/red_team.py
CHANGED
|
@@ -21,6 +21,7 @@ from .dto import (
|
|
|
21
21
|
RedTeamRiskMitigationGuardrailsPolicyResponse,
|
|
22
22
|
RedTeamRiskMitigationSystemPromptConfig,
|
|
23
23
|
RedTeamRiskMitigationSystemPromptResponse,
|
|
24
|
+
RedTeamFindingsResponse
|
|
24
25
|
)
|
|
25
26
|
|
|
26
27
|
|
|
@@ -537,3 +538,30 @@ class RedTeamClient(BaseClient):
|
|
|
537
538
|
if isinstance(response, dict) and response.get("error"):
|
|
538
539
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
539
540
|
return RedTeamRiskMitigationSystemPromptResponse.from_dict(response)
|
|
541
|
+
|
|
542
|
+
def get_findings(self, redteam_summary):
|
|
543
|
+
"""
|
|
544
|
+
Get findings and insights based on red team summary data.
|
|
545
|
+
|
|
546
|
+
Parameters:
|
|
547
|
+
- redteam_summary (dict or ResultSummary): Red team test summary data
|
|
548
|
+
|
|
549
|
+
Returns:
|
|
550
|
+
- RedTeamFindingsResponse: Response from the API containing findings
|
|
551
|
+
"""
|
|
552
|
+
# Allow passing in either a dict or a ResultSummary instance
|
|
553
|
+
if hasattr(redteam_summary, "to_dict"):
|
|
554
|
+
redteam_summary = redteam_summary.to_dict()
|
|
555
|
+
|
|
556
|
+
payload = {
|
|
557
|
+
"redteam_summary": redteam_summary
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
try:
|
|
561
|
+
response = self._request("POST", "/redteam/findings", json=payload)
|
|
562
|
+
if response.get("error"):
|
|
563
|
+
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
564
|
+
return RedTeamFindingsResponse.from_dict(response)
|
|
565
|
+
except Exception as e:
|
|
566
|
+
raise RedTeamClientError(str(e))
|
|
567
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: enkryptai-sdk
|
|
3
|
+
Version: 1.0.23
|
|
4
|
+
Summary: A Python SDK with guardrails and red teaming functionality for API interactions
|
|
5
|
+
Home-page: https://github.com/enkryptai/enkryptai-sdk
|
|
6
|
+
Author: Enkrypt AI Team
|
|
7
|
+
Author-email: software@enkryptai.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: home-page
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-python
|
|
22
|
+
Dynamic: summary
|
|
23
|
+
|
|
24
|
+
# Enkrypt AI Python SDK
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
A Python SDK with Guardrails, Code of Conduct Policies, Endpoints (Models), Deployments, AI Proxy, Datasets, Red Team, etc. functionality for API interactions.
|
|
29
|
+
|
|
30
|
+
**See documentation at [https://docs.enkryptai.com/libraries/python/introduction](https://docs.enkryptai.com/libraries/python/introduction)**
|
|
31
|
+
|
|
32
|
+
See [https://pypi.org/project/enkryptai-sdk](https://pypi.org/project/enkryptai-sdk)
|
|
33
|
+
|
|
34
|
+
## Copyright, License and Terms of Use
|
|
35
|
+
|
|
36
|
+
© 2025 Enkrypt AI. All rights reserved.
|
|
37
|
+
|
|
38
|
+
Enkrypt AI software is provided under a proprietary license. Unauthorized use, reproduction, or distribution of this software or any portion of it is strictly prohibited.
|
|
39
|
+
|
|
40
|
+
Terms of Use: [https://www.enkryptai.com/terms-and-conditions](https://www.enkryptai.com/terms-and-conditions)
|
|
41
|
+
|
|
42
|
+
Enkrypt AI and the Enkrypt AI logo are trademarks of Enkrypt AI, Inc.
|
|
@@ -6,23 +6,23 @@ enkryptai_sdk/config.py,sha256=zUlWFr33JVz_kzUl3JalXeq-s1q0Qvyi4HBrGk0CTBU,9402
|
|
|
6
6
|
enkryptai_sdk/datasets.py,sha256=RQIR6spI2STXeVolYzBt6gPv6PD5AGh9krs16aKWdWA,6067
|
|
7
7
|
enkryptai_sdk/deployments.py,sha256=A7XZ2JwrMod9V4_aV8bFY_Soh9E3jHdwaTuJ9BwXuyk,4215
|
|
8
8
|
enkryptai_sdk/evals.py,sha256=BywyEgIT7xdJ58svO_sDNOMVowdB0RTGoAZPEbCnDVo,2595
|
|
9
|
-
enkryptai_sdk/guardrails.py,sha256=
|
|
9
|
+
enkryptai_sdk/guardrails.py,sha256=iEngSpkzZBB3EkJGxUxUgYF0Av4N2XWMN-BlAkRDle4,19856
|
|
10
10
|
enkryptai_sdk/guardrails_old.py,sha256=SgzPZkTzbAPD9XfmYNG6M1-TrzbhDHpAkI3FjnVWS_s,6434
|
|
11
11
|
enkryptai_sdk/models.py,sha256=0R0I4KOq0aDNi5utabANot-E8dT9GqiSsgrcI9RULHM,8932
|
|
12
|
-
enkryptai_sdk/red_team.py,sha256=
|
|
12
|
+
enkryptai_sdk/red_team.py,sha256=w52gPteGaH6iEBThjIYxLAV1bXXTorgxST_TOnGMT88,20917
|
|
13
13
|
enkryptai_sdk/response.py,sha256=43JRubzgGCpoVxYNzBZY0AlUgLbfcXD_AwD7wU3qY9o,4086
|
|
14
14
|
enkryptai_sdk/dto/__init__.py,sha256=wHgIv_OCnVMJOys-vqImF59ifogDrMcgxVRmfNayVvc,2761
|
|
15
15
|
enkryptai_sdk/dto/ai_proxy.py,sha256=clwMN4xdH8Zr55dnhilHbs-qaHRlCOrLPrij0Zd1Av0,11283
|
|
16
16
|
enkryptai_sdk/dto/base.py,sha256=y77kQL1X7389ifSVNc0E7CUFNxACh5AM3ml9YPon1KY,2822
|
|
17
|
-
enkryptai_sdk/dto/coc.py,sha256=
|
|
17
|
+
enkryptai_sdk/dto/coc.py,sha256=9D5mmSdmC_guV75ml48PPLZD_zFa5FjxRwlTqHrmdak,5071
|
|
18
18
|
enkryptai_sdk/dto/common.py,sha256=lrWMu4FKUGCN2dbS9fT4yNtfiPm1cNN16J4eCe4_tBM,1812
|
|
19
|
-
enkryptai_sdk/dto/datasets.py,sha256=
|
|
20
|
-
enkryptai_sdk/dto/deployments.py,sha256=
|
|
21
|
-
enkryptai_sdk/dto/guardrails.py,sha256=
|
|
22
|
-
enkryptai_sdk/dto/models.py,sha256=
|
|
23
|
-
enkryptai_sdk/dto/red_team.py,sha256=
|
|
24
|
-
enkryptai_sdk-1.0.
|
|
25
|
-
enkryptai_sdk-1.0.
|
|
26
|
-
enkryptai_sdk-1.0.
|
|
27
|
-
enkryptai_sdk-1.0.
|
|
28
|
-
enkryptai_sdk-1.0.
|
|
19
|
+
enkryptai_sdk/dto/datasets.py,sha256=FiVwbEZ04jPajnlBfgw1Aj83iAhup3Ut7GOymq73OMg,5073
|
|
20
|
+
enkryptai_sdk/dto/deployments.py,sha256=v--UrwkuXP4xTsPbmVruYj-g3JEQXepBRQfr-Gsv3aA,11744
|
|
21
|
+
enkryptai_sdk/dto/guardrails.py,sha256=n73uPmK9fCIqqxv1rNecYUX4v5ePdIjxSBD4jIhwDe8,55966
|
|
22
|
+
enkryptai_sdk/dto/models.py,sha256=AwqYMBZckJ0RdeU89I-3CYJ03c-VLdHf5zD5PSbU3JQ,14585
|
|
23
|
+
enkryptai_sdk/dto/red_team.py,sha256=rV7bYVb5YSxnrhLwNiTlKWy0ZTXK4zhmPgVoLJQMMoo,28802
|
|
24
|
+
enkryptai_sdk-1.0.23.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
|
+
enkryptai_sdk-1.0.23.dist-info/METADATA,sha256=CMSsEyEBXxGhIciL2JgGg2slVeEbxw9OeLRpVtUp1qM,1644
|
|
26
|
+
enkryptai_sdk-1.0.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
27
|
+
enkryptai_sdk-1.0.23.dist-info/top_level.txt,sha256=s2X9UJJwvJamNmr6ZXWyyQe60sXtQGWFuaBYfhgHI_4,14
|
|
28
|
+
enkryptai_sdk-1.0.23.dist-info/RECORD,,
|