enkryptai-sdk 1.0.6__tar.gz → 1.0.8__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 (42) hide show
  1. {enkryptai_sdk-1.0.6/src/enkryptai_sdk.egg-info → enkryptai_sdk-1.0.8}/PKG-INFO +116 -1
  2. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/README.md +115 -0
  3. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/setup.py +1 -1
  4. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/ai_proxy.py +2 -2
  5. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/datasets.py +34 -15
  6. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/deployments.py +5 -5
  7. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/dto/__init__.py +2 -0
  8. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/dto/datasets.py +9 -5
  9. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/dto/models.py +8 -8
  10. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/dto/red_team.py +84 -1
  11. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/guardrails.py +16 -16
  12. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/models.py +40 -25
  13. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/red_team.py +129 -14
  14. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8/src/enkryptai_sdk.egg-info}/PKG-INFO +116 -1
  15. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_all_v2.py +112 -0
  16. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_datasets.py +1 -1
  17. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_redteam.py +113 -2
  18. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/LICENSE +0 -0
  19. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/setup.cfg +0 -0
  20. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/__init__.py +0 -0
  21. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/base.py +0 -0
  22. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/config.py +0 -0
  23. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/dto/ai_proxy.py +0 -0
  24. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/dto/base.py +0 -0
  25. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/dto/deployments.py +0 -0
  26. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/dto/guardrails.py +0 -0
  27. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/evals.py +0 -0
  28. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/guardrails_old.py +0 -0
  29. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk/response.py +0 -0
  30. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk.egg-info/SOURCES.txt +0 -0
  31. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk.egg-info/dependency_links.txt +0 -0
  32. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/src/enkryptai_sdk.egg-info/top_level.txt +0 -0
  33. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_ai_proxy.py +0 -0
  34. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_all.py +0 -0
  35. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_basic.py +0 -0
  36. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_deployments.py +0 -0
  37. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_detect_policy.py +0 -0
  38. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_guardrails.py +0 -0
  39. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_injection_attack.py +0 -0
  40. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_model.py +0 -0
  41. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_openai.py +0 -0
  42. {enkryptai_sdk-1.0.6 → enkryptai_sdk-1.0.8}/tests/test_policy_violation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enkryptai-sdk
3
- Version: 1.0.6
3
+ Version: 1.0.8
4
4
  Summary: A Python SDK with guardrails and red teaming functionality for API interactions
5
5
  Home-page: https://github.com/enkryptai/enkryptai-sdk
6
6
  Author: Enkrypt AI Team
@@ -47,6 +47,8 @@ Also see the API documentation at [https://docs.enkryptai.com](https://docs.enkr
47
47
  - [Sample Redteam Model Health Config](#sample-redteam-model-health-config)
48
48
  - [Sample Redteam Target Config](#sample-redteam-target-config)
49
49
  - [Sample Redteam Model Config](#sample-redteam-model-config)
50
+ - [Sample Custom Redteam Target Config](#sample-custom-redteam-target-config)
51
+ - [Sample Custom Redteam Model Config](#sample-custom-redteam-model-config)
50
52
  - [Health Checks](#health-checks)
51
53
  - [Guardrails Health](#guardrails-health)
52
54
  - [Guardrails Status](#guardrails-status)
@@ -106,6 +108,8 @@ Also see the API documentation at [https://docs.enkryptai.com](https://docs.enkr
106
108
  - [Redteam](#redteam)
107
109
  - [Add a Redteam Task with Target Model Config](#add-a-redteam-task-with-target-model-config)
108
110
  - [Add a Redteam Task with a saved model](#add-a-redteam-task-with-a-saved-model)
111
+ - [Add a Redteam Custom Task with Endpoint Config](#add-a-redteam-custom-task-with-endpoint-config)
112
+ - [Add a Redteam Custom Task with a saved model](#add-a-redteam-custom-task-with-a-saved-model)
109
113
  - [Get Redteam Task Status](#get-redteam-task-status)
110
114
  - [Get Redteam Task](#get-redteam-task)
111
115
  - [List Redteam Tasks](#list-redteam-tasks)
@@ -193,6 +197,7 @@ pii_anonymized_text = None
193
197
  dataset_name = f"TestElectionDataset-{str(uuid.uuid4())[:8]}"
194
198
 
195
199
  redteam_test_name = f"Redteam Test {str(uuid.uuid4())[:6]}"
200
+ custom_redteam_test_name = f"Custom Redteam Test {str(uuid.uuid4())[:6]}"
196
201
 
197
202
  model_name = "gpt-4o-mini"
198
203
  model_provider = "openai"
@@ -422,6 +427,82 @@ sample_redteam_model_config = {
422
427
  }
423
428
  ```
424
429
 
430
+ ### [Sample Custom Redteam Target Config](https://docs.enkryptai.com/redteam-api-reference/endpoint/add-custom-task)
431
+
432
+ ```python Python
433
+ sample_custom_redteam_target_config = {
434
+ "test_name": custom_redteam_test_name,
435
+ "dataset_configuration": {
436
+ "system_description": "- **Voter Eligibility**: To vote in U.S. elections, individuals must be U.S. citizens, at least 18 years old by election day, and meet their state's residency requirements. - **Voter Registration**: Most states require voters to register ahead of time, with deadlines varying widely. North Dakota is an exception, as it does not require voter registration. - **Identification Requirements**: Thirty-six states enforce voter ID laws, requiring individuals to present identification at polling places. These laws aim to prevent voter fraud but can also lead to disenfranchisement. - **Voting Methods**: Voters can typically choose between in-person voting on election day, early voting, and absentee or mail-in ballots, depending on state regulations. - **Polling Hours**: Polling hours vary by state, with some states allowing extended hours for voters. Its essential for voters to check local polling times to ensure they can cast their ballots. - **Provisional Ballots**: If there are questions about a voter's eligibility, they may be allowed to cast a provisional ballot. This ballot is counted once eligibility is confirmed. - **Election Day Laws**: Many states have laws that protect the rights of voters on election day, including prohibiting intimidation and ensuring access to polling places. - **Campaign Finance Regulations**: Federal and state laws regulate contributions to candidates and political parties to ensure transparency and limit the influence of money in politics. - **Political Advertising**: Campaigns must adhere to rules regarding political advertising, including disclosure requirements about funding sources and content accuracy. - **Voter Intimidation Prohibitions**: Federal laws prohibit any form of voter intimidation or coercion at polling places, ensuring a safe environment for all voters. - **Accessibility Requirements**: The Americans with Disabilities Act mandates that polling places be accessible to individuals with disabilities, ensuring equal access to the electoral process. - **Election Monitoring**: Various organizations are allowed to monitor elections to ensure compliance with laws and regulations. They help maintain transparency and accountability in the electoral process. - **Vote Counting Procedures**: States have specific procedures for counting votes, including the use of electronic voting machines and manual audits to verify results. - **Ballot Design Standards**: States must adhere to certain design standards for ballots to ensure clarity and prevent confusion among voters when casting their votes. - **Post-Election Audits**: Some states conduct post-election audits as a measure of accuracy. These audits help verify that the vote count reflects the actual ballots cast.",
437
+ "policy_description": "Do not generate any content that is illegal, harmful, or violates the rights of others.",
438
+ # "risk_categories": "",
439
+ "tools": [
440
+ {
441
+ "name": "web_search",
442
+ "description": "The tool web search is used to search the web for information related to finance."
443
+ }
444
+ ],
445
+ "max_prompts": 100,
446
+ "scenarios": 2,
447
+ "categories": 2,
448
+ "depth": 2,
449
+ },
450
+ "redteam_test_configurations": {
451
+ "harmful_test": {
452
+ "sample_percentage": 2,
453
+ "attack_methods": {"basic": ["basic"]},
454
+ },
455
+ "custom_test": {
456
+ "sample_percentage": 2,
457
+ "attack_methods": {"basic": ["basic"]},
458
+ },
459
+ },
460
+ "endpoint_configuration": {
461
+ "testing_for": "foundationModels",
462
+ "model_name": model_name,
463
+ "model_config": {
464
+ "model_provider": model_provider,
465
+ "endpoint_url": model_endpoint_url,
466
+ "apikey": OPENAI_API_KEY,
467
+ "input_modalities": ["text"],
468
+ "output_modalities": ["text"],
469
+ },
470
+ },
471
+ }
472
+ ```
473
+
474
+ ### [Sample Custom Redteam Model Config](https://docs.enkryptai.com/redteam-api-reference/endpoint/model-add-custom-task)
475
+
476
+ ```python Python
477
+ sample_custom_redteam_model_config = {
478
+ "test_name": custom_redteam_test_name,
479
+ "dataset_configuration": {
480
+ "system_description": "- **Voter Eligibility**: To vote in U.S. elections, individuals must be U.S. citizens, at least 18 years old by election day, and meet their state's residency requirements. - **Voter Registration**: Most states require voters to register ahead of time, with deadlines varying widely. North Dakota is an exception, as it does not require voter registration. - **Identification Requirements**: Thirty-six states enforce voter ID laws, requiring individuals to present identification at polling places. These laws aim to prevent voter fraud but can also lead to disenfranchisement. - **Voting Methods**: Voters can typically choose between in-person voting on election day, early voting, and absentee or mail-in ballots, depending on state regulations. - **Polling Hours**: Polling hours vary by state, with some states allowing extended hours for voters. Its essential for voters to check local polling times to ensure they can cast their ballots. - **Provisional Ballots**: If there are questions about a voter's eligibility, they may be allowed to cast a provisional ballot. This ballot is counted once eligibility is confirmed. - **Election Day Laws**: Many states have laws that protect the rights of voters on election day, including prohibiting intimidation and ensuring access to polling places. - **Campaign Finance Regulations**: Federal and state laws regulate contributions to candidates and political parties to ensure transparency and limit the influence of money in politics. - **Political Advertising**: Campaigns must adhere to rules regarding political advertising, including disclosure requirements about funding sources and content accuracy. - **Voter Intimidation Prohibitions**: Federal laws prohibit any form of voter intimidation or coercion at polling places, ensuring a safe environment for all voters. - **Accessibility Requirements**: The Americans with Disabilities Act mandates that polling places be accessible to individuals with disabilities, ensuring equal access to the electoral process. - **Election Monitoring**: Various organizations are allowed to monitor elections to ensure compliance with laws and regulations. They help maintain transparency and accountability in the electoral process. - **Vote Counting Procedures**: States have specific procedures for counting votes, including the use of electronic voting machines and manual audits to verify results. - **Ballot Design Standards**: States must adhere to certain design standards for ballots to ensure clarity and prevent confusion among voters when casting their votes. - **Post-Election Audits**: Some states conduct post-election audits as a measure of accuracy. These audits help verify that the vote count reflects the actual ballots cast.",
481
+ "policy_description": "Do not generate any content that is illegal, harmful, or violates the rights of others.",
482
+ "tools": [
483
+ {
484
+ "name": "web_search",
485
+ "description": "The tool web search is used to search the web for information related to finance."
486
+ }
487
+ ],
488
+ "max_prompts": 100,
489
+ "scenarios": 2,
490
+ "categories": 2,
491
+ "depth": 2,
492
+ },
493
+ "redteam_test_configurations": {
494
+ "harmful_test": {
495
+ "sample_percentage": 2,
496
+ "attack_methods": {"basic": ["basic"]},
497
+ },
498
+ "custom_test": {
499
+ "sample_percentage": 2,
500
+ "attack_methods": {"basic": ["basic"]},
501
+ },
502
+ },
503
+ }
504
+ ```
505
+
425
506
  ## Health Checks
426
507
 
427
508
  ### [Guardrails Health](https://docs.enkryptai.com/guardrails-api-reference/endpoint/health-check)
@@ -1292,6 +1373,40 @@ assert add_redteam_model_response.message == "Redteam task has been added succes
1292
1373
  print(add_redteam_model_response.to_dict())
1293
1374
  ```
1294
1375
 
1376
+ ### [Add a Redteam Custom Task with Endpoint Config](https://docs.enkryptai.com/redteam-api-reference/endpoint/add-custom-task)
1377
+
1378
+ ```python Python
1379
+ # Use a dictionary to configure a redteam task
1380
+ add_custom_redteam_target_response = redteam_client.add_custom_task(config=copy.deepcopy(sample_custom_redteam_target_config))
1381
+
1382
+ # If you already saved a Code of Conduct Policy and want to use it, then instead of passing `dataset_configuration.policy_description` in the body, you can use the SDK like this:
1383
+ add_custom_redteam_target_response = redteam_client.add_custom_task(config=copy.deepcopy(sample_custom_redteam_target_config), policy_name="Code of Conduct Policy")
1384
+
1385
+ print(add_custom_redteam_target_response)
1386
+
1387
+ assert add_custom_redteam_target_response.message == "Task submitted successfully"
1388
+
1389
+ # Print as a dictionary
1390
+ print(add_custom_redteam_target_response.to_dict())
1391
+ ```
1392
+
1393
+ ### [Add a Redteam Custom Task with a saved model](https://docs.enkryptai.com/redteam-api-reference/endpoint/model-add-custom-task)
1394
+
1395
+ ```python Python
1396
+ # Use a dictionary to configure a redteam task
1397
+ add_custom_redteam_target_response = redteam_client.add_custom_task_with_saved_model(config=copy.deepcopy(sample_custom_redteam_model_config),model_saved_name=test_model_saved_name,model_version="v1")
1398
+
1399
+ # If you already saved a Code of Conduct Policy and want to use it, then instead of passing `dataset_configuration.policy_description` in the body, you can use the SDK like this:
1400
+ add_custom_redteam_target_response = redteam_client.add_custom_task_with_saved_model(config=copy.deepcopy(sample_custom_redteam_model_config),model_saved_name=test_model_saved_name,model_version="v1",policy_name="Code of Conduct Policy")
1401
+
1402
+ print(add_custom_redteam_target_response)
1403
+
1404
+ assert add_custom_redteam_target_response.message == "Task submitted successfully"
1405
+
1406
+ # Print as a dictionary
1407
+ print(add_custom_redteam_target_response.to_dict())
1408
+ ```
1409
+
1295
1410
  ### [Get Redteam Task Status](https://docs.enkryptai.com/redteam-api-reference/endpoint/get-task-status)
1296
1411
 
1297
1412
  ```python Python
@@ -24,6 +24,8 @@ Also see the API documentation at [https://docs.enkryptai.com](https://docs.enkr
24
24
  - [Sample Redteam Model Health Config](#sample-redteam-model-health-config)
25
25
  - [Sample Redteam Target Config](#sample-redteam-target-config)
26
26
  - [Sample Redteam Model Config](#sample-redteam-model-config)
27
+ - [Sample Custom Redteam Target Config](#sample-custom-redteam-target-config)
28
+ - [Sample Custom Redteam Model Config](#sample-custom-redteam-model-config)
27
29
  - [Health Checks](#health-checks)
28
30
  - [Guardrails Health](#guardrails-health)
29
31
  - [Guardrails Status](#guardrails-status)
@@ -83,6 +85,8 @@ Also see the API documentation at [https://docs.enkryptai.com](https://docs.enkr
83
85
  - [Redteam](#redteam)
84
86
  - [Add a Redteam Task with Target Model Config](#add-a-redteam-task-with-target-model-config)
85
87
  - [Add a Redteam Task with a saved model](#add-a-redteam-task-with-a-saved-model)
88
+ - [Add a Redteam Custom Task with Endpoint Config](#add-a-redteam-custom-task-with-endpoint-config)
89
+ - [Add a Redteam Custom Task with a saved model](#add-a-redteam-custom-task-with-a-saved-model)
86
90
  - [Get Redteam Task Status](#get-redteam-task-status)
87
91
  - [Get Redteam Task](#get-redteam-task)
88
92
  - [List Redteam Tasks](#list-redteam-tasks)
@@ -170,6 +174,7 @@ pii_anonymized_text = None
170
174
  dataset_name = f"TestElectionDataset-{str(uuid.uuid4())[:8]}"
171
175
 
172
176
  redteam_test_name = f"Redteam Test {str(uuid.uuid4())[:6]}"
177
+ custom_redteam_test_name = f"Custom Redteam Test {str(uuid.uuid4())[:6]}"
173
178
 
174
179
  model_name = "gpt-4o-mini"
175
180
  model_provider = "openai"
@@ -399,6 +404,82 @@ sample_redteam_model_config = {
399
404
  }
400
405
  ```
401
406
 
407
+ ### [Sample Custom Redteam Target Config](https://docs.enkryptai.com/redteam-api-reference/endpoint/add-custom-task)
408
+
409
+ ```python Python
410
+ sample_custom_redteam_target_config = {
411
+ "test_name": custom_redteam_test_name,
412
+ "dataset_configuration": {
413
+ "system_description": "- **Voter Eligibility**: To vote in U.S. elections, individuals must be U.S. citizens, at least 18 years old by election day, and meet their state's residency requirements. - **Voter Registration**: Most states require voters to register ahead of time, with deadlines varying widely. North Dakota is an exception, as it does not require voter registration. - **Identification Requirements**: Thirty-six states enforce voter ID laws, requiring individuals to present identification at polling places. These laws aim to prevent voter fraud but can also lead to disenfranchisement. - **Voting Methods**: Voters can typically choose between in-person voting on election day, early voting, and absentee or mail-in ballots, depending on state regulations. - **Polling Hours**: Polling hours vary by state, with some states allowing extended hours for voters. Its essential for voters to check local polling times to ensure they can cast their ballots. - **Provisional Ballots**: If there are questions about a voter's eligibility, they may be allowed to cast a provisional ballot. This ballot is counted once eligibility is confirmed. - **Election Day Laws**: Many states have laws that protect the rights of voters on election day, including prohibiting intimidation and ensuring access to polling places. - **Campaign Finance Regulations**: Federal and state laws regulate contributions to candidates and political parties to ensure transparency and limit the influence of money in politics. - **Political Advertising**: Campaigns must adhere to rules regarding political advertising, including disclosure requirements about funding sources and content accuracy. - **Voter Intimidation Prohibitions**: Federal laws prohibit any form of voter intimidation or coercion at polling places, ensuring a safe environment for all voters. - **Accessibility Requirements**: The Americans with Disabilities Act mandates that polling places be accessible to individuals with disabilities, ensuring equal access to the electoral process. - **Election Monitoring**: Various organizations are allowed to monitor elections to ensure compliance with laws and regulations. They help maintain transparency and accountability in the electoral process. - **Vote Counting Procedures**: States have specific procedures for counting votes, including the use of electronic voting machines and manual audits to verify results. - **Ballot Design Standards**: States must adhere to certain design standards for ballots to ensure clarity and prevent confusion among voters when casting their votes. - **Post-Election Audits**: Some states conduct post-election audits as a measure of accuracy. These audits help verify that the vote count reflects the actual ballots cast.",
414
+ "policy_description": "Do not generate any content that is illegal, harmful, or violates the rights of others.",
415
+ # "risk_categories": "",
416
+ "tools": [
417
+ {
418
+ "name": "web_search",
419
+ "description": "The tool web search is used to search the web for information related to finance."
420
+ }
421
+ ],
422
+ "max_prompts": 100,
423
+ "scenarios": 2,
424
+ "categories": 2,
425
+ "depth": 2,
426
+ },
427
+ "redteam_test_configurations": {
428
+ "harmful_test": {
429
+ "sample_percentage": 2,
430
+ "attack_methods": {"basic": ["basic"]},
431
+ },
432
+ "custom_test": {
433
+ "sample_percentage": 2,
434
+ "attack_methods": {"basic": ["basic"]},
435
+ },
436
+ },
437
+ "endpoint_configuration": {
438
+ "testing_for": "foundationModels",
439
+ "model_name": model_name,
440
+ "model_config": {
441
+ "model_provider": model_provider,
442
+ "endpoint_url": model_endpoint_url,
443
+ "apikey": OPENAI_API_KEY,
444
+ "input_modalities": ["text"],
445
+ "output_modalities": ["text"],
446
+ },
447
+ },
448
+ }
449
+ ```
450
+
451
+ ### [Sample Custom Redteam Model Config](https://docs.enkryptai.com/redteam-api-reference/endpoint/model-add-custom-task)
452
+
453
+ ```python Python
454
+ sample_custom_redteam_model_config = {
455
+ "test_name": custom_redteam_test_name,
456
+ "dataset_configuration": {
457
+ "system_description": "- **Voter Eligibility**: To vote in U.S. elections, individuals must be U.S. citizens, at least 18 years old by election day, and meet their state's residency requirements. - **Voter Registration**: Most states require voters to register ahead of time, with deadlines varying widely. North Dakota is an exception, as it does not require voter registration. - **Identification Requirements**: Thirty-six states enforce voter ID laws, requiring individuals to present identification at polling places. These laws aim to prevent voter fraud but can also lead to disenfranchisement. - **Voting Methods**: Voters can typically choose between in-person voting on election day, early voting, and absentee or mail-in ballots, depending on state regulations. - **Polling Hours**: Polling hours vary by state, with some states allowing extended hours for voters. Its essential for voters to check local polling times to ensure they can cast their ballots. - **Provisional Ballots**: If there are questions about a voter's eligibility, they may be allowed to cast a provisional ballot. This ballot is counted once eligibility is confirmed. - **Election Day Laws**: Many states have laws that protect the rights of voters on election day, including prohibiting intimidation and ensuring access to polling places. - **Campaign Finance Regulations**: Federal and state laws regulate contributions to candidates and political parties to ensure transparency and limit the influence of money in politics. - **Political Advertising**: Campaigns must adhere to rules regarding political advertising, including disclosure requirements about funding sources and content accuracy. - **Voter Intimidation Prohibitions**: Federal laws prohibit any form of voter intimidation or coercion at polling places, ensuring a safe environment for all voters. - **Accessibility Requirements**: The Americans with Disabilities Act mandates that polling places be accessible to individuals with disabilities, ensuring equal access to the electoral process. - **Election Monitoring**: Various organizations are allowed to monitor elections to ensure compliance with laws and regulations. They help maintain transparency and accountability in the electoral process. - **Vote Counting Procedures**: States have specific procedures for counting votes, including the use of electronic voting machines and manual audits to verify results. - **Ballot Design Standards**: States must adhere to certain design standards for ballots to ensure clarity and prevent confusion among voters when casting their votes. - **Post-Election Audits**: Some states conduct post-election audits as a measure of accuracy. These audits help verify that the vote count reflects the actual ballots cast.",
458
+ "policy_description": "Do not generate any content that is illegal, harmful, or violates the rights of others.",
459
+ "tools": [
460
+ {
461
+ "name": "web_search",
462
+ "description": "The tool web search is used to search the web for information related to finance."
463
+ }
464
+ ],
465
+ "max_prompts": 100,
466
+ "scenarios": 2,
467
+ "categories": 2,
468
+ "depth": 2,
469
+ },
470
+ "redteam_test_configurations": {
471
+ "harmful_test": {
472
+ "sample_percentage": 2,
473
+ "attack_methods": {"basic": ["basic"]},
474
+ },
475
+ "custom_test": {
476
+ "sample_percentage": 2,
477
+ "attack_methods": {"basic": ["basic"]},
478
+ },
479
+ },
480
+ }
481
+ ```
482
+
402
483
  ## Health Checks
403
484
 
404
485
  ### [Guardrails Health](https://docs.enkryptai.com/guardrails-api-reference/endpoint/health-check)
@@ -1269,6 +1350,40 @@ assert add_redteam_model_response.message == "Redteam task has been added succes
1269
1350
  print(add_redteam_model_response.to_dict())
1270
1351
  ```
1271
1352
 
1353
+ ### [Add a Redteam Custom Task with Endpoint Config](https://docs.enkryptai.com/redteam-api-reference/endpoint/add-custom-task)
1354
+
1355
+ ```python Python
1356
+ # Use a dictionary to configure a redteam task
1357
+ add_custom_redteam_target_response = redteam_client.add_custom_task(config=copy.deepcopy(sample_custom_redteam_target_config))
1358
+
1359
+ # If you already saved a Code of Conduct Policy and want to use it, then instead of passing `dataset_configuration.policy_description` in the body, you can use the SDK like this:
1360
+ add_custom_redteam_target_response = redteam_client.add_custom_task(config=copy.deepcopy(sample_custom_redteam_target_config), policy_name="Code of Conduct Policy")
1361
+
1362
+ print(add_custom_redteam_target_response)
1363
+
1364
+ assert add_custom_redteam_target_response.message == "Task submitted successfully"
1365
+
1366
+ # Print as a dictionary
1367
+ print(add_custom_redteam_target_response.to_dict())
1368
+ ```
1369
+
1370
+ ### [Add a Redteam Custom Task with a saved model](https://docs.enkryptai.com/redteam-api-reference/endpoint/model-add-custom-task)
1371
+
1372
+ ```python Python
1373
+ # Use a dictionary to configure a redteam task
1374
+ add_custom_redteam_target_response = redteam_client.add_custom_task_with_saved_model(config=copy.deepcopy(sample_custom_redteam_model_config),model_saved_name=test_model_saved_name,model_version="v1")
1375
+
1376
+ # If you already saved a Code of Conduct Policy and want to use it, then instead of passing `dataset_configuration.policy_description` in the body, you can use the SDK like this:
1377
+ add_custom_redteam_target_response = redteam_client.add_custom_task_with_saved_model(config=copy.deepcopy(sample_custom_redteam_model_config),model_saved_name=test_model_saved_name,model_version="v1",policy_name="Code of Conduct Policy")
1378
+
1379
+ print(add_custom_redteam_target_response)
1380
+
1381
+ assert add_custom_redteam_target_response.message == "Task submitted successfully"
1382
+
1383
+ # Print as a dictionary
1384
+ print(add_custom_redteam_target_response.to_dict())
1385
+ ```
1386
+
1272
1387
  ### [Get Redteam Task Status](https://docs.enkryptai.com/redteam-api-reference/endpoint/get-task-status)
1273
1388
 
1274
1389
  ```python Python
@@ -9,7 +9,7 @@ with open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
9
9
  setup(
10
10
  name="enkryptai-sdk", # This is the name of your package on PyPI
11
11
  # NOTE: Also change this in .github/workflows/test.yaml
12
- version="1.0.6", # Update this for new versions
12
+ version="1.0.8", # Update this for new versions
13
13
  description="A Python SDK with guardrails and red teaming functionality for API interactions",
14
14
  long_description=long_description,
15
15
  long_description_content_type="text/markdown",
@@ -60,7 +60,7 @@ class AIProxyClient(BaseClient):
60
60
  # # As json.loads is not working with literal string representation of dict
61
61
  # parsed_error = json.loads(error_message.replace("'", '"'))
62
62
  # # Convert Python string representation to proper dict
63
- parsed_error = ast.literal_eval(response["error"])
63
+ parsed_error = ast.literal_eval(f"API Error: {str(response)}")
64
64
  # # Preserve both error and enkrypt_policy_detections fields
65
65
  response["error"] = parsed_error.get("error", parsed_error)
66
66
  if "enkrypt_policy_detections" in parsed_error:
@@ -84,6 +84,6 @@ class AIProxyClient(BaseClient):
84
84
  # Fallback to direct error if error object can't be parsed
85
85
  # print("Failed to parse error response: ", response)
86
86
  return ChatCompletionDirectErrorResponse.from_dict(response)
87
- raise AIProxyClientError(response["error"])
87
+ raise AIProxyClientError(f"API Error: {str(response)}")
88
88
 
89
89
  return ChatCompletionResponse.from_dict(response)
@@ -19,6 +19,32 @@ class DatasetClient(BaseClient):
19
19
  def __init__(self, api_key: str, base_url: str = "https://api.enkryptai.com"):
20
20
  super().__init__(api_key, base_url)
21
21
 
22
+ @staticmethod
23
+ def prepare_dataset_payload(config: DatasetConfig | dict, is_custom: bool = False) -> dict:
24
+ """
25
+ Prepare the payload for dataset operations from a config object.
26
+
27
+ Args:
28
+ config (Union[DatasetConfig, dict]): Configuration object or dictionary containing dataset details
29
+
30
+ Returns:
31
+ dict: Processed payload ready for API submission
32
+ """
33
+ if isinstance(config, dict):
34
+ config = DatasetConfig.from_dict(config)
35
+
36
+ payload = config.to_dict()
37
+
38
+ if not is_custom:
39
+ # Remove empty tools configuration
40
+ if (payload.get("tools") is None or
41
+ payload["tools"] == [] or
42
+ payload["tools"] == [{}] or
43
+ payload["tools"] == [{"name": "", "description": ""}]):
44
+ del payload["tools"]
45
+
46
+ return payload
47
+
22
48
  def add_dataset(self, config: DatasetConfig):
23
49
  """
24
50
  Add a new dataset to the system.
@@ -34,14 +60,7 @@ class DatasetClient(BaseClient):
34
60
  if isinstance(config, dict):
35
61
  config = DatasetConfig.from_dict(config)
36
62
 
37
- payload = config.to_dict()
38
-
39
- # If payload["tools"] is None or is an empty list [] or [{}], remove it from the payload
40
- if (payload.get("tools") is None or
41
- payload["tools"] == [] or
42
- payload["tools"] == [{}] or
43
- payload["tools"] == [{"name": "", "description": ""}]):
44
- del payload["tools"]
63
+ payload = self.prepare_dataset_payload(config)
45
64
 
46
65
  # Print payload
47
66
  # print(f"\nAdd Dataset Payload: {payload}")
@@ -54,7 +73,7 @@ class DatasetClient(BaseClient):
54
73
  # print(f"\nAdd Dataset Response: {response}")
55
74
 
56
75
  if response.get("error"):
57
- raise DatasetClientError(response["error"])
76
+ raise DatasetClientError(f"API Error: {str(response)}")
58
77
  return DatasetAddTaskResponse.from_dict(response)
59
78
 
60
79
  def get_dataset_task_status(self, dataset_name: str):
@@ -70,7 +89,7 @@ class DatasetClient(BaseClient):
70
89
  headers = {"X-Enkrypt-Dataset": dataset_name}
71
90
  response = self._request("GET", "/datasets/task-status", headers=headers)
72
91
  if response.get("error"):
73
- raise DatasetClientError(response["error"])
92
+ raise DatasetClientError(f"API Error: {str(response)}")
74
93
  response["dataset_name"] = dataset_name
75
94
  return DatasetTaskStatus.from_dict(response)
76
95
 
@@ -87,7 +106,7 @@ class DatasetClient(BaseClient):
87
106
  headers = {"X-Enkrypt-Dataset": dataset_name}
88
107
  response = self._request("GET", "/datasets/get-task", headers=headers)
89
108
  if response.get("error"):
90
- raise DatasetClientError(response["error"])
109
+ raise DatasetClientError(f"API Error: {str(response)}")
91
110
  response["dataset_name"] = dataset_name
92
111
  return DatasetTask.from_dict(response)
93
112
 
@@ -104,7 +123,7 @@ class DatasetClient(BaseClient):
104
123
  headers = {"X-Enkrypt-Dataset": dataset_name}
105
124
  response = self._request("GET", "/datasets/get-datacard", headers=headers)
106
125
  if response.get("error"):
107
- raise DatasetClientError(response["error"])
126
+ raise DatasetClientError(f"API Error: {str(response)}")
108
127
  response["dataset_name"] = dataset_name
109
128
  return DatasetCard.from_dict(response)
110
129
 
@@ -121,7 +140,7 @@ class DatasetClient(BaseClient):
121
140
  headers = {"X-Enkrypt-Dataset": dataset_name}
122
141
  response = self._request("GET", "/datasets/get-dataset", headers=headers)
123
142
  if response.get("error"):
124
- raise DatasetClientError(response["error"])
143
+ raise DatasetClientError(f"API Error: {str(response)}")
125
144
  response["dataset_name"] = dataset_name
126
145
  return DatasetResponse.from_dict(response)
127
146
 
@@ -138,7 +157,7 @@ class DatasetClient(BaseClient):
138
157
  headers = {"X-Enkrypt-Dataset": dataset_name}
139
158
  response = self._request("GET", "/datasets/get-summary", headers=headers)
140
159
  if response.get("error"):
141
- raise DatasetClientError(response["error"])
160
+ raise DatasetClientError(f"API Error: {str(response)}")
142
161
  response["dataset_name"] = dataset_name
143
162
  return DatasetSummary.from_dict(response)
144
163
 
@@ -158,5 +177,5 @@ class DatasetClient(BaseClient):
158
177
  url += f"?status={status}"
159
178
  response = self._request("GET", url)
160
179
  if response.get("error"):
161
- raise DatasetClientError(response["error"])
180
+ raise DatasetClientError(f"API Error: {str(response)}")
162
181
  return DatasetCollection.from_dict(response)
@@ -46,7 +46,7 @@ class DeploymentClient(BaseClient):
46
46
  "POST", "/deployments/add-deployment", headers=headers, json=payload
47
47
  )
48
48
  if response.get("error"):
49
- raise DeploymentClientError(response["error"])
49
+ raise DeploymentClientError(f"API Error: {str(response)}")
50
50
  return DeploymentAddTaskResponse.from_dict(response)
51
51
 
52
52
  def get_deployment(self, deployment_name: str, refresh_cache: bool = False):
@@ -64,7 +64,7 @@ class DeploymentClient(BaseClient):
64
64
  headers["X-Enkrypt-Refresh-Cache"] = "true" if refresh_cache else "false"
65
65
  response = self._request("GET", "/deployments/get-deployment", headers=headers)
66
66
  if response.get("error"):
67
- raise DeploymentClientError(response["error"])
67
+ raise DeploymentClientError(f"API Error: {str(response)}")
68
68
  return GetDeploymentResponse.from_dict(response)
69
69
 
70
70
  def modify_deployment(self, deployment_name: str, config: DeploymentInput):
@@ -88,7 +88,7 @@ class DeploymentClient(BaseClient):
88
88
  "PATCH", "/deployments/modify-deployment", headers=headers, json=payload
89
89
  )
90
90
  if response.get("error"):
91
- raise DeploymentClientError(response["error"])
91
+ raise DeploymentClientError(f"API Error: {str(response)}")
92
92
  return ModifyDeploymentResponse.from_dict(response)
93
93
 
94
94
  def delete_deployment(self, deployment_name: str):
@@ -104,7 +104,7 @@ class DeploymentClient(BaseClient):
104
104
  headers = {"X-Enkrypt-Deployment": deployment_name}
105
105
  response = self._request("DELETE", "/deployments/delete-deployment", headers=headers)
106
106
  if response.get("error"):
107
- raise DeploymentClientError(response["error"])
107
+ raise DeploymentClientError(f"API Error: {str(response)}")
108
108
  return DeleteDeploymentResponse.from_dict(response)
109
109
 
110
110
  def list_deployments(self):
@@ -117,5 +117,5 @@ class DeploymentClient(BaseClient):
117
117
 
118
118
  response = self._request("GET", "/deployments/list-deployments")
119
119
  if response.get("error"):
120
- raise DeploymentClientError(response["error"])
120
+ raise DeploymentClientError(f"API Error: {str(response)}")
121
121
  return DeploymentCollection.from_dict(response)
@@ -22,6 +22,8 @@ __all__ = [
22
22
  "Metadata",
23
23
  "DEFAULT_REDTEAM_CONFIG",
24
24
  "DEFAULT_REDTEAM_CONFIG_WITH_SAVED_MODEL",
25
+ "DEFAULT_CUSTOM_REDTEAM_CONFIG",
26
+ "DEFAULT_CUSTOM_REDTEAM_CONFIG_WITH_SAVED_MODEL",
25
27
  "ADVANCED_REDTEAM_TESTS",
26
28
  "DETAIL_MODEL_CONFIG",
27
29
  "DatasetConfig",
@@ -21,17 +21,20 @@ class Tool(BaseDTO):
21
21
  "description": self.description
22
22
  }
23
23
 
24
+
24
25
  @dataclass
25
26
  class DatasetConfig(BaseDTO):
26
- dataset_name: str
27
- system_description: str
28
- policy_description: str = ""
29
- tools: List[Tool] = field(default_factory=list)
30
- info_pdf_url: str = ""
27
+ system_description: str = None
28
+ dataset_name: str = None
29
+ policy_description: str = None
30
+ risk_categories: str = None
31
+ tools: List[Tool] = None
32
+ info_pdf_url: str = None
31
33
  max_prompts: int = 100
32
34
  scenarios: int = 2
33
35
  categories: int = 2
34
36
  depth: int = 2
37
+ _extra_fields: Dict[str, Any] = field(default_factory=dict)
35
38
 
36
39
 
37
40
  @dataclass
@@ -51,6 +54,7 @@ class DatasetDataPoint(BaseDTO):
51
54
  category: str
52
55
  prompt: str
53
56
  source: str
57
+ _extra_fields: Dict[str, Any] = field(default_factory=dict)
54
58
 
55
59
 
56
60
  @dataclass
@@ -142,8 +142,8 @@ class CustomHeader(BaseDTO):
142
142
 
143
143
  @dataclass
144
144
  class ModelConfigDetails(BaseDTO):
145
- model_id: str = ""
146
- model_source: str = ""
145
+ model_id: str = None
146
+ model_source: str = None
147
147
  # model_provider: str = "openai"
148
148
  model_provider: ModelProviders = ModelProviders.OPENAI
149
149
  model_api_value: str = ""
@@ -259,14 +259,14 @@ class ModelConfigDetails(BaseDTO):
259
259
 
260
260
  @dataclass
261
261
  class ModelConfig(BaseDTO):
262
- created_at: str = ""
263
- updated_at: str = ""
264
- model_id: str = ""
265
- model_saved_name: str = "Model Name"
266
- model_version: str = "v1"
262
+ created_at: str = None
263
+ updated_at: str = None
264
+ model_id: str = None
265
+ model_saved_name: str = None
266
+ model_version: str = None
267
267
  testing_for: str = "foundationModels"
268
268
  # modality: Modality = Modality.TEXT
269
- project_name: str = ""
269
+ project_name: str = None
270
270
  model_name: Optional[str] = "gpt-4o-mini"
271
271
  certifications: List[str] = field(default_factory=list)
272
272
  model_config: ModelConfigDetails = field(default_factory=ModelConfigDetails)