enkryptai-sdk 1.0.19__py3-none-any.whl → 1.0.22__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.
@@ -1625,4 +1625,117 @@ class GuardrailsPolicyAtomizerResponse(BaseDTO):
1625
1625
  f"Total Rules: {self.total_rules}\n"
1626
1626
  f"Message: {self.message}"
1627
1627
  )
1628
+
1629
+
1630
+ @dataclass
1631
+ class GuardrailsViolation(BaseDTO):
1632
+ unsafe_content: str
1633
+ chunk_type: str
1634
+ triggered_detectors: List[str]
1635
+ guardrails_result: Dict[str, Any]
1636
+ _extra_fields: Dict[str, Any] = field(default_factory=dict)
1637
+
1638
+ @classmethod
1639
+ def from_dict(cls, data: Dict[str, Any]) -> "GuardrailsViolation":
1640
+ return cls(
1641
+ unsafe_content=data.get("unsafe_content", ""),
1642
+ chunk_type=data.get("chunk_type", ""),
1643
+ triggered_detectors=data.get("triggered_detectors", []),
1644
+ guardrails_result=data.get("guardrails_result", {})
1645
+ )
1628
1646
 
1647
+ def to_dict(self) -> Dict[str, Any]:
1648
+ result = {
1649
+ "unsafe_content": self.unsafe_content,
1650
+ "chunk_type": self.chunk_type,
1651
+ "triggered_detectors": self.triggered_detectors,
1652
+ "guardrails_result": self.guardrails_result
1653
+ }
1654
+ result.update(self._extra_fields)
1655
+ return result
1656
+
1657
+
1658
+ @dataclass
1659
+ class GuardrailsScanUrlResponse(BaseDTO):
1660
+ url: str
1661
+ violations: List[GuardrailsViolation]
1662
+ combined_highlight_url: str
1663
+ _extra_fields: Dict[str, Any] = field(default_factory=dict)
1664
+
1665
+ @classmethod
1666
+ def from_dict(cls, data: Dict[str, Any]) -> "GuardrailsScanUrlResponse":
1667
+ violations_data = data.get("violations", [])
1668
+ violations = [GuardrailsViolation.from_dict(violation) for violation in violations_data]
1669
+
1670
+ return cls(
1671
+ url=data.get("url", ""),
1672
+ violations=violations,
1673
+ combined_highlight_url=data.get("combined_highlight_url", "")
1674
+ )
1675
+
1676
+ def to_dict(self) -> Dict[str, Any]:
1677
+ result = {
1678
+ "url": self.url,
1679
+ "violations": [violation.to_dict() for violation in self.violations],
1680
+ "combined_highlight_url": self.combined_highlight_url
1681
+ }
1682
+ result.update(self._extra_fields)
1683
+ return result
1684
+
1685
+ def has_violations(self) -> bool:
1686
+ """
1687
+ Check if any detectors found violations in the URL content.
1688
+
1689
+ Returns:
1690
+ bool: True if any violations were detected, False otherwise
1691
+ """
1692
+ return len(self.violations) > 0
1693
+
1694
+ def get_violations(self) -> List[str]:
1695
+ """
1696
+ Get a list of detector names that found violations.
1697
+
1698
+ Returns:
1699
+ List[str]: Names of detectors that reported violations
1700
+ """
1701
+ triggered_detectors = []
1702
+ for violation in self.violations:
1703
+ triggered_detectors.extend(violation.triggered_detectors)
1704
+ # Remove duplicates while preserving order
1705
+ return list(dict.fromkeys(triggered_detectors))
1706
+
1707
+ def is_safe(self) -> bool:
1708
+ """
1709
+ Check if the URL content is safe (no violations detected).
1710
+
1711
+ Returns:
1712
+ bool: True if no violations were detected, False otherwise
1713
+ """
1714
+ return not self.has_violations()
1715
+
1716
+ def is_attack(self) -> bool:
1717
+ """
1718
+ Check if the URL content is attacked (violations detected).
1719
+
1720
+ Returns:
1721
+ bool: True if violations were detected, False otherwise
1722
+ """
1723
+ return self.has_violations()
1724
+
1725
+ def __str__(self) -> str:
1726
+ """
1727
+ String representation of the response.
1728
+
1729
+ Returns:
1730
+ str: A formatted string showing URL, violations and status
1731
+ """
1732
+ violations = self.get_violations()
1733
+ status = "UNSAFE" if violations else "SAFE"
1734
+
1735
+ if violations:
1736
+ violation_str = f"Violations detected: {', '.join(violations)}"
1737
+ else:
1738
+ violation_str = "No violations detected"
1739
+
1740
+ return f"URL Scan Result for {self.url}\nStatus: {status}\n{violation_str}"
1741
+
@@ -422,6 +422,7 @@ class RedTeamTestConfigurations(BaseDTO):
422
422
  reliability_and_observability_test: TestConfig = field(default=None)
423
423
  agent_behaviour_test: TestConfig = field(default=None)
424
424
  access_control_and_permissions_test: TestConfig = field(default=None)
425
+ tool_extraction_test: TestConfig = field(default=None)
425
426
  _extra_fields: Dict[str, Any] = field(default_factory=dict)
426
427
 
427
428
  @classmethod
@@ -799,6 +800,50 @@ class RedTeamRiskMitigationSystemPromptResponse(BaseDTO):
799
800
  "message": self.message,
800
801
  }
801
802
 
803
+ @dataclass
804
+ class RedTeamKeyFinding(BaseDTO):
805
+ text: str
806
+ _extra_fields: Dict[str, Any] = field(default_factory=dict)
807
+
808
+ @classmethod
809
+ def from_dict(cls, data: Dict[str, Any]) -> "RedTeamKeyFinding":
810
+ return cls(
811
+ text=data.get("text", "")
812
+ )
813
+
814
+ def to_dict(self) -> Dict[str, Any]:
815
+ result = {
816
+ "text": self.text
817
+ }
818
+ result.update(self._extra_fields)
819
+ return result
820
+
821
+
822
+ @dataclass
823
+ class RedTeamFindingsResponse(BaseDTO):
824
+ key_findings: List[RedTeamKeyFinding] = field(default_factory=list)
825
+ message: str = ""
826
+ _extra_fields: Dict[str, Any] = field(default_factory=dict)
827
+
828
+ @classmethod
829
+ def from_dict(cls, data: Dict[str, Any]) -> "RedTeamFindingsResponse":
830
+ key_findings_data = data.get("key_findings", [])
831
+ key_findings = [RedTeamKeyFinding.from_dict(finding) for finding in key_findings_data]
832
+
833
+ return cls(
834
+ key_findings=key_findings,
835
+ message=data.get("message", "")
836
+ )
837
+
838
+ def to_dict(self) -> Dict[str, Any]:
839
+ result = {
840
+ "key_findings": [finding.to_dict() for finding in self.key_findings],
841
+ "message": self.message
842
+ }
843
+ result.update(self._extra_fields)
844
+ return result
845
+
846
+
802
847
 
803
848
  # Default configurations
804
849
  DEFAULT_REDTEAM_CONFIG = RedTeamConfig()
@@ -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.22
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
+ ![Python SDK test](https://github.com/enkryptai/enkryptai-sdk/actions/workflows/test.yaml/badge.svg)
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,10 +6,10 @@ 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=NluimOA0gM9N3S_q47LTUeG97t9PlYqPHlZahDPkJvI,16365
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=7bWNognd6TCzNQDocml-C_f6u5z1MeursSe3Rtz16Sw,19929
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
@@ -18,11 +18,11 @@ enkryptai_sdk/dto/coc.py,sha256=Lp2aat_24J4KuUg4BeJl9S39tEak8Bw15eJ4cQDrRQk,4749
18
18
  enkryptai_sdk/dto/common.py,sha256=lrWMu4FKUGCN2dbS9fT4yNtfiPm1cNN16J4eCe4_tBM,1812
19
19
  enkryptai_sdk/dto/datasets.py,sha256=RFA9CmbhD-QDDyweBq_k9iBd00b6I6SWmdP9DPNd9fc,5002
20
20
  enkryptai_sdk/dto/deployments.py,sha256=_tdSyRTJvthjLTbOxFO4f2P6vgirDsF3in5_gXE3a_U,11288
21
- enkryptai_sdk/dto/guardrails.py,sha256=NUVz59c-lnlTOwg72QIk62-USfHO-dpS5u2Hr6q9QGA,51774
21
+ enkryptai_sdk/dto/guardrails.py,sha256=cfL18qfDtNXG4SONCVONHYAKS9J3m0EAqUdTeeUoZK8,55510
22
22
  enkryptai_sdk/dto/models.py,sha256=4aeI9-iHPhSX5duRMTQRbkXhplAhN8OHw3gWdTxrafU,14531
23
- enkryptai_sdk/dto/red_team.py,sha256=VoNQVte__bXf2-wXgTDMEk--7KSvQm7ZR45WXPPneHU,27324
24
- enkryptai_sdk-1.0.19.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- enkryptai_sdk-1.0.19.dist-info/METADATA,sha256=mtGop_UEL2riS3hMqfD3NOcIorcb5pOyqC0jddvVwFE,73153
26
- enkryptai_sdk-1.0.19.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- enkryptai_sdk-1.0.19.dist-info/top_level.txt,sha256=s2X9UJJwvJamNmr6ZXWyyQe60sXtQGWFuaBYfhgHI_4,14
28
- enkryptai_sdk-1.0.19.dist-info/RECORD,,
23
+ enkryptai_sdk/dto/red_team.py,sha256=KRR_gDBTrrN6VEiSLaXDIqciY7N7OelIAQNmzCAsZgU,28675
24
+ enkryptai_sdk-1.0.22.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
+ enkryptai_sdk-1.0.22.dist-info/METADATA,sha256=EDFqSS5spOBzcyNAgtqm8DnUeGE7AtxXRsDEIdHWZTw,1644
26
+ enkryptai_sdk-1.0.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
+ enkryptai_sdk-1.0.22.dist-info/top_level.txt,sha256=s2X9UJJwvJamNmr6ZXWyyQe60sXtQGWFuaBYfhgHI_4,14
28
+ enkryptai_sdk-1.0.22.dist-info/RECORD,,