pangea-sdk 6.2.0b2__py3-none-any.whl → 6.3.0__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.
@@ -1,13 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
- from collections.abc import Mapping
4
- from typing import Annotated, Generic, Literal, Optional, Union, overload
3
+ from collections.abc import Sequence
4
+ from typing import Generic, Literal, Optional, overload
5
5
 
6
- from pydantic import BaseModel, ConfigDict, Field, RootModel
6
+ from pydantic import BaseModel, ConfigDict
7
7
  from typing_extensions import TypeVar
8
8
 
9
9
  from pangea.config import PangeaConfig
10
- from pangea.response import APIRequestModel, APIResponseModel, PangeaDateTime, PangeaResponse, PangeaResponseResult
10
+ from pangea.response import APIRequestModel, APIResponseModel, PangeaResponse, PangeaResponseResult
11
11
  from pangea.services.base import ServiceBase
12
12
 
13
13
  # This is named "prompt injection" in the API spec even though it is also used
@@ -21,6 +21,13 @@ MaliciousEntityAction = Literal["report", "defang", "disabled", "block"]
21
21
  PiiEntityAction = Literal["disabled", "report", "block", "mask", "partial_masking", "replacement", "hash", "fpe"]
22
22
 
23
23
 
24
+ class Message(BaseModel):
25
+ model_config = ConfigDict(extra="forbid")
26
+
27
+ role: str
28
+ content: str
29
+
30
+
24
31
  class CodeDetectionOverride(APIRequestModel):
25
32
  disabled: Optional[bool] = None
26
33
  action: Optional[Literal["report", "block"]] = None
@@ -278,14 +285,14 @@ class TextGuardDetectors(APIResponseModel):
278
285
  code_detection: Optional[TextGuardDetector[CodeDetectionResult]] = None
279
286
 
280
287
 
281
- class TextGuardResult(PangeaResponseResult, Generic[_T]):
288
+ class TextGuardResult(PangeaResponseResult):
282
289
  detectors: TextGuardDetectors
283
290
  """Result of the recipe analyzing and input prompt."""
284
291
 
285
292
  prompt_text: Optional[str] = None
286
293
  """Updated prompt text, if applicable."""
287
294
 
288
- prompt_messages: Optional[_T] = None
295
+ prompt_messages: Optional[object] = None
289
296
  """Updated structured prompt, if applicable."""
290
297
 
291
298
  blocked: bool
@@ -301,405 +308,6 @@ class TextGuardResult(PangeaResponseResult, Generic[_T]):
301
308
  """
302
309
 
303
310
 
304
- class Areas(BaseModel):
305
- model_config = ConfigDict(extra="forbid")
306
-
307
- text_guard: bool
308
-
309
-
310
- class AuditDataActivityConfig(BaseModel):
311
- model_config = ConfigDict(extra="forbid")
312
-
313
- enabled: bool
314
- audit_service_config_id: str
315
- areas: Areas
316
-
317
-
318
- class PromptGuard(BaseModel):
319
- model_config = ConfigDict(extra="forbid")
320
-
321
- enabled: Optional[bool] = None
322
- config_id: Optional[str] = None
323
- confidence_threshold: Optional[float] = None
324
-
325
-
326
- class IpIntel(BaseModel):
327
- model_config = ConfigDict(extra="forbid")
328
-
329
- enabled: Optional[bool] = None
330
- config_id: Optional[str] = None
331
- reputation_provider: Optional[str] = None
332
- risk_threshold: Optional[float] = None
333
-
334
-
335
- class UserIntel(BaseModel):
336
- model_config = ConfigDict(extra="forbid")
337
-
338
- enabled: Optional[bool] = None
339
- config_id: Optional[str] = None
340
- breach_provider: Optional[str] = None
341
-
342
-
343
- class UrlIntel(BaseModel):
344
- model_config = ConfigDict(extra="forbid")
345
-
346
- enabled: Optional[bool] = None
347
- config_id: Optional[str] = None
348
- reputation_provider: Optional[str] = None
349
- risk_threshold: Optional[float] = None
350
-
351
-
352
- class DomainIntel(BaseModel):
353
- model_config = ConfigDict(extra="forbid")
354
-
355
- enabled: Optional[bool] = None
356
- config_id: Optional[str] = None
357
- reputation_provider: Optional[str] = None
358
- risk_threshold: Optional[float] = None
359
-
360
-
361
- class FileScan(BaseModel):
362
- model_config = ConfigDict(extra="forbid")
363
-
364
- enabled: Optional[bool] = None
365
- config_id: Optional[str] = None
366
- scan_provider: Optional[str] = None
367
- risk_threshold: Optional[float] = None
368
-
369
-
370
- class Redact(BaseModel):
371
- model_config = ConfigDict(extra="forbid")
372
-
373
- enabled: Optional[bool] = None
374
- config_id: Optional[str] = None
375
-
376
-
377
- class Vault(BaseModel):
378
- model_config = ConfigDict(extra="forbid")
379
-
380
- config_id: Optional[str] = None
381
-
382
-
383
- class Lingua(BaseModel):
384
- model_config = ConfigDict(extra="forbid")
385
-
386
- enabled: Optional[bool] = None
387
-
388
-
389
- class Code(BaseModel):
390
- model_config = ConfigDict(extra="forbid")
391
-
392
- enabled: Optional[bool] = None
393
-
394
-
395
- class ConnectionsConfig(BaseModel):
396
- model_config = ConfigDict(extra="forbid")
397
-
398
- prompt_guard: Optional[PromptGuard] = None
399
- ip_intel: Optional[IpIntel] = None
400
- user_intel: Optional[UserIntel] = None
401
- url_intel: Optional[UrlIntel] = None
402
- domain_intel: Optional[DomainIntel] = None
403
- file_scan: Optional[FileScan] = None
404
- redact: Optional[Redact] = None
405
- vault: Optional[Vault] = None
406
- lingua: Optional[Lingua] = None
407
- code: Optional[Code] = None
408
-
409
-
410
- class PartialMasking(BaseModel):
411
- masking_type: Optional[Literal["unmask", "mask"]] = "unmask"
412
- unmasked_from_left: Annotated[Optional[int], Field(ge=0)] = None
413
- unmasked_from_right: Annotated[Optional[int], Field(ge=0)] = None
414
- masked_from_left: Annotated[Optional[int], Field(ge=0)] = None
415
- masked_from_right: Annotated[Optional[int], Field(ge=0)] = None
416
- chars_to_ignore: Optional[list[CharsToIgnoreItem]] = None
417
- masking_char: Annotated[Optional[str], Field(max_length=1, min_length=1)] = "*"
418
-
419
-
420
- class RuleRedactionConfig1(BaseModel):
421
- model_config = ConfigDict(extra="forbid")
422
-
423
- redaction_type: Literal[
424
- "mask",
425
- "partial_masking",
426
- "replacement",
427
- "hash",
428
- "detect_only",
429
- "fpe",
430
- "mask",
431
- "detect_only",
432
- ]
433
- redaction_value: Optional[str] = None
434
- partial_masking: Optional[PartialMasking] = None
435
- hash: Optional[Hash] = None
436
- fpe_alphabet: Optional[
437
- Literal[
438
- "numeric",
439
- "alphalower",
440
- "alphaupper",
441
- "alpha",
442
- "alphanumericlower",
443
- "alphanumericupper",
444
- "alphanumeric",
445
- ]
446
- ] = None
447
-
448
-
449
- class PartialMasking1(BaseModel):
450
- masking_type: Optional[Literal["unmask", "mask"]] = "unmask"
451
- unmasked_from_left: Annotated[Optional[int], Field(ge=0)] = None
452
- unmasked_from_right: Annotated[Optional[int], Field(ge=0)] = None
453
- masked_from_left: Annotated[Optional[int], Field(ge=0)] = None
454
- masked_from_right: Annotated[Optional[int], Field(ge=0)] = None
455
- chars_to_ignore: Optional[list[CharsToIgnoreItem]] = None
456
- masking_char: Annotated[Optional[str], Field(max_length=1, min_length=1)] = "*"
457
-
458
-
459
- class RuleRedactionConfig2(BaseModel):
460
- model_config = ConfigDict(extra="forbid")
461
-
462
- redaction_type: Literal["replacement"]
463
- redaction_value: str
464
- partial_masking: Optional[PartialMasking1] = None
465
- hash: Optional[Hash] = None
466
- fpe_alphabet: Optional[
467
- Literal[
468
- "numeric",
469
- "alphalower",
470
- "alphaupper",
471
- "alpha",
472
- "alphanumericlower",
473
- "alphanumericupper",
474
- "alphanumeric",
475
- ]
476
- ] = None
477
-
478
-
479
- class PartialMasking2(BaseModel):
480
- masking_type: Optional[Literal["unmask", "mask"]] = "unmask"
481
- unmasked_from_left: Annotated[Optional[int], Field(ge=0)] = None
482
- unmasked_from_right: Annotated[Optional[int], Field(ge=0)] = None
483
- masked_from_left: Annotated[Optional[int], Field(ge=0)] = None
484
- masked_from_right: Annotated[Optional[int], Field(ge=0)] = None
485
- chars_to_ignore: Optional[list[CharsToIgnoreItem]] = None
486
- masking_char: Annotated[Optional[str], Field(max_length=1, min_length=1)] = "*"
487
-
488
-
489
- class RuleRedactionConfig3(BaseModel):
490
- model_config = ConfigDict(extra="forbid")
491
-
492
- redaction_type: Literal["partial_masking"]
493
- redaction_value: str
494
- partial_masking: PartialMasking2
495
- hash: Optional[Hash] = None
496
- fpe_alphabet: Optional[
497
- Literal[
498
- "numeric",
499
- "alphalower",
500
- "alphaupper",
501
- "alpha",
502
- "alphanumericlower",
503
- "alphanumericupper",
504
- "alphanumeric",
505
- ]
506
- ] = None
507
-
508
-
509
- class PartialMasking3(BaseModel):
510
- masking_type: Optional[Literal["unmask", "mask"]] = "unmask"
511
- unmasked_from_left: Annotated[Optional[int], Field(ge=0)] = None
512
- unmasked_from_right: Annotated[Optional[int], Field(ge=0)] = None
513
- masked_from_left: Annotated[Optional[int], Field(ge=0)] = None
514
- masked_from_right: Annotated[Optional[int], Field(ge=0)] = None
515
- chars_to_ignore: Optional[list[CharsToIgnoreItem]] = None
516
- masking_char: Annotated[Optional[str], Field(max_length=1, min_length=1)] = "*"
517
-
518
-
519
- class RuleRedactionConfig4(BaseModel):
520
- model_config = ConfigDict(extra="forbid")
521
-
522
- redaction_type: Literal["hash"]
523
- redaction_value: str
524
- partial_masking: PartialMasking3
525
- hash: Optional[Hash] = None
526
- fpe_alphabet: Optional[
527
- Literal[
528
- "numeric",
529
- "alphalower",
530
- "alphaupper",
531
- "alpha",
532
- "alphanumericlower",
533
- "alphanumericupper",
534
- "alphanumeric",
535
- ]
536
- ] = None
537
-
538
-
539
- class CharsToIgnoreItem(RootModel[str]):
540
- root: Annotated[str, Field(max_length=1, min_length=1)]
541
-
542
-
543
- class PartialMasking4(BaseModel):
544
- masking_type: Optional[Literal["unmask", "mask"]] = "unmask"
545
- unmasked_from_left: Annotated[Optional[int], Field(ge=0)] = None
546
- unmasked_from_right: Annotated[Optional[int], Field(ge=0)] = None
547
- masked_from_left: Annotated[Optional[int], Field(ge=0)] = None
548
- masked_from_right: Annotated[Optional[int], Field(ge=0)] = None
549
- chars_to_ignore: Optional[list[CharsToIgnoreItem]] = None
550
- masking_char: Annotated[Optional[str], Field(max_length=1, min_length=1)] = "*"
551
-
552
-
553
- class Hash(BaseModel):
554
- hash_type: Literal["md5", "sha256"]
555
- """The type of hashing algorithm"""
556
-
557
-
558
- class RuleRedactionConfig5(BaseModel):
559
- model_config = ConfigDict(extra="forbid")
560
-
561
- redaction_type: Literal["fpe"]
562
- redaction_value: str
563
- partial_masking: PartialMasking4
564
- hash: Optional[Hash] = None
565
- fpe_alphabet: Optional[
566
- Literal[
567
- "numeric",
568
- "alphalower",
569
- "alphaupper",
570
- "alpha",
571
- "alphanumericlower",
572
- "alphanumericupper",
573
- "alphanumeric",
574
- ]
575
- ] = None
576
-
577
-
578
- class Rule(BaseModel):
579
- model_config = ConfigDict(extra="forbid")
580
- redact_rule_id: str
581
- redaction: Union[
582
- RuleRedactionConfig1,
583
- RuleRedactionConfig2,
584
- RuleRedactionConfig3,
585
- RuleRedactionConfig4,
586
- RuleRedactionConfig5,
587
- ]
588
- block: Optional[bool] = None
589
- disabled: Optional[bool] = None
590
- reputation_check: Optional[bool] = None
591
- transform_if_malicious: Optional[bool] = None
592
-
593
-
594
- class Settings(BaseModel):
595
- rules: Optional[list[Rule]] = None
596
-
597
-
598
- class DetectorSetting(BaseModel):
599
- model_config = ConfigDict(extra="forbid")
600
-
601
- detector_name: str
602
- state: Literal["disabled", "enabled"]
603
- settings: Settings
604
-
605
-
606
- class RedactConnectorSettings(BaseModel):
607
- fpe_tweak_vault_secret_id: Optional[str] = None
608
-
609
-
610
- class ConnectorSettings(BaseModel):
611
- model_config = ConfigDict(extra="forbid")
612
-
613
- redact: Optional[RedactConnectorSettings] = None
614
-
615
-
616
- class RecipeConfig(BaseModel):
617
- model_config = ConfigDict(extra="forbid")
618
-
619
- name: str
620
- description: str
621
- version: Optional[str] = ""
622
- detectors: Optional[list[DetectorSetting]] = None
623
- """Setting for Detectors"""
624
- connector_settings: Optional[ConnectorSettings] = None
625
-
626
-
627
- class ServiceConfig(PangeaResponseResult):
628
- id: Optional[str] = None
629
- name: Optional[str] = None
630
- audit_data_activity: Optional[AuditDataActivityConfig] = None
631
- connections: Optional[ConnectionsConfig] = None
632
- recipes: Optional[dict[str, RecipeConfig]] = None
633
-
634
-
635
- class ServiceConfigFilter(BaseModel):
636
- model_config = ConfigDict(extra="forbid")
637
-
638
- id: Optional[str] = None
639
- """
640
- Only records where id equals this value.
641
- """
642
- id__contains: Optional[list[str]] = None
643
- """
644
- Only records where id includes each substring.
645
- """
646
- id__in: Optional[list[str]] = None
647
- """
648
- Only records where id equals one of the provided substrings.
649
- """
650
- created_at: Optional[PangeaDateTime] = None
651
- """
652
- Only records where created_at equals this value.
653
- """
654
- created_at__gt: Optional[PangeaDateTime] = None
655
- """
656
- Only records where created_at is greater than this value.
657
- """
658
- created_at__gte: Optional[PangeaDateTime] = None
659
- """
660
- Only records where created_at is greater than or equal to this value.
661
- """
662
- created_at__lt: Optional[PangeaDateTime] = None
663
- """
664
- Only records where created_at is less than this value.
665
- """
666
- created_at__lte: Optional[PangeaDateTime] = None
667
- """
668
- Only records where created_at is less than or equal to this value.
669
- """
670
- updated_at: Optional[PangeaDateTime] = None
671
- """
672
- Only records where updated_at equals this value.
673
- """
674
- updated_at__gt: Optional[PangeaDateTime] = None
675
- """
676
- Only records where updated_at is greater than this value.
677
- """
678
- updated_at__gte: Optional[PangeaDateTime] = None
679
- """
680
- Only records where updated_at is greater than or equal to this value.
681
- """
682
- updated_at__lt: Optional[PangeaDateTime] = None
683
- """
684
- Only records where updated_at is less than this value.
685
- """
686
- updated_at__lte: Optional[PangeaDateTime] = None
687
- """
688
- Only records where updated_at is less than or equal to this value.
689
- """
690
-
691
-
692
- class ServiceConfigsPage(PangeaResponseResult):
693
- count: Optional[int] = None
694
- """The total number of service configs matched by the list request."""
695
- last: Optional[str] = None
696
- """
697
- Used to fetch the next page of the current listing when provided in a
698
- repeated request's last parameter.
699
- """
700
- items: Optional[list[ServiceConfig]] = None
701
-
702
-
703
311
  class AIGuard(ServiceBase):
704
312
  """AI Guard service client.
705
313
 
@@ -748,7 +356,7 @@ class AIGuard(ServiceBase):
748
356
  debug: bool | None = None,
749
357
  overrides: Overrides | None = None,
750
358
  log_fields: LogFields | None = None,
751
- ) -> PangeaResponse[TextGuardResult[None]]:
359
+ ) -> PangeaResponse[TextGuardResult]:
752
360
  """
753
361
  Text Guard for scanning LLM inputs and outputs
754
362
 
@@ -776,12 +384,12 @@ class AIGuard(ServiceBase):
776
384
  def guard_text(
777
385
  self,
778
386
  *,
779
- messages: _T,
387
+ messages: Sequence[Message],
780
388
  recipe: str | None = None,
781
389
  debug: bool | None = None,
782
390
  overrides: Overrides | None = None,
783
391
  log_fields: LogFields | None = None,
784
- ) -> PangeaResponse[TextGuardResult[_T]]:
392
+ ) -> PangeaResponse[TextGuardResult]:
785
393
  """
786
394
  Text Guard for scanning LLM inputs and outputs
787
395
 
@@ -803,19 +411,19 @@ class AIGuard(ServiceBase):
803
411
  log_field: Additional fields to include in activity log
804
412
 
805
413
  Examples:
806
- response = ai_guard.guard_text(messages=[{"role": "user", "content": "hello world"}])
414
+ response = ai_guard.guard_text(messages=[Message(role="user", content="hello world")])
807
415
  """
808
416
 
809
- def guard_text( # type: ignore[misc]
417
+ def guard_text(
810
418
  self,
811
419
  text: str | None = None,
812
420
  *,
813
- messages: _T | None = None,
421
+ messages: Sequence[Message] | None = None,
814
422
  recipe: str | None = None,
815
423
  debug: bool | None = None,
816
424
  overrides: Overrides | None = None,
817
425
  log_fields: LogFields | None = None,
818
- ) -> PangeaResponse[TextGuardResult[None]]:
426
+ ) -> PangeaResponse[TextGuardResult]:
819
427
  """
820
428
  Text Guard for scanning LLM inputs and outputs
821
429
 
@@ -858,81 +466,3 @@ class AIGuard(ServiceBase):
858
466
  "log_fields": log_fields,
859
467
  },
860
468
  )
861
-
862
- def get_service_config(self, id: str) -> PangeaResponse[ServiceConfig]:
863
- """
864
- OperationId: ai_guard_post_v1beta_config
865
- """
866
- return self.request.post("v1beta/config", data={"id": id}, result_class=ServiceConfig)
867
-
868
- def create_service_config(
869
- self,
870
- name: str,
871
- *,
872
- id: str | None = None,
873
- audit_data_activity: AuditDataActivityConfig | None = None,
874
- connections: ConnectionsConfig | None = None,
875
- recipes: Mapping[str, RecipeConfig] | None = None,
876
- ) -> PangeaResponse[ServiceConfig]:
877
- """
878
- OperationId: ai_guard_post_v1beta_config_create
879
- """
880
- return self.request.post(
881
- "v1beta/config/create",
882
- data={
883
- "name": name,
884
- "id": id,
885
- "audit_data_activity": audit_data_activity,
886
- "connections": connections,
887
- "recipes": recipes,
888
- },
889
- result_class=ServiceConfig,
890
- )
891
-
892
- def update_service_config(
893
- self,
894
- id: str,
895
- name: str,
896
- *,
897
- audit_data_activity: AuditDataActivityConfig | None = None,
898
- connections: ConnectionsConfig | None = None,
899
- recipes: Mapping[str, RecipeConfig] | None = None,
900
- ) -> PangeaResponse[ServiceConfig]:
901
- """
902
- OperationId: ai_guard_post_v1beta_config_update
903
- """
904
- return self.request.post(
905
- "v1beta/config/update",
906
- data={
907
- "id": id,
908
- "name": name,
909
- "audit_data_activity": audit_data_activity,
910
- "connections": connections,
911
- "recipes": recipes,
912
- },
913
- result_class=ServiceConfig,
914
- )
915
-
916
- def delete_service_config(self, id: str) -> PangeaResponse[ServiceConfig]:
917
- """
918
- OperationId: ai_guard_post_v1beta_config_delete
919
- """
920
- return self.request.post("v1beta/config/delete", data={"id": id}, result_class=ServiceConfig)
921
-
922
- def list_service_configs(
923
- self,
924
- *,
925
- filter: ServiceConfigFilter | None = None,
926
- last: str | None = None,
927
- order: Literal["asc", "desc"] | None = None,
928
- order_by: Literal["id", "created_at", "updated_at"] | None = None,
929
- size: int | None = None,
930
- ) -> PangeaResponse[ServiceConfigsPage]:
931
- """
932
- OperationId: ai_guard_post_v1beta_config_list
933
- """
934
- return self.request.post(
935
- "v1beta/config/list",
936
- data={"filter": filter, "last": last, "order": order, "order_by": order_by, "size": size},
937
- result_class=ServiceConfigsPage,
938
- )