pangea-sdk 6.2.0b2__py3-none-any.whl → 6.4.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,12 @@
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
7
6
  from typing_extensions import TypeVar
8
7
 
9
8
  from pangea.config import PangeaConfig
10
- from pangea.response import APIRequestModel, APIResponseModel, PangeaDateTime, PangeaResponse, PangeaResponseResult
9
+ from pangea.response import APIRequestModel, APIResponseModel, PangeaResponse, PangeaResponseResult
11
10
  from pangea.services.base import ServiceBase
12
11
 
13
12
  # This is named "prompt injection" in the API spec even though it is also used
@@ -21,21 +20,29 @@ MaliciousEntityAction = Literal["report", "defang", "disabled", "block"]
21
20
  PiiEntityAction = Literal["disabled", "report", "block", "mask", "partial_masking", "replacement", "hash", "fpe"]
22
21
 
23
22
 
23
+ class Message(APIRequestModel):
24
+ role: str
25
+ content: str
26
+
27
+
24
28
  class CodeDetectionOverride(APIRequestModel):
25
29
  disabled: Optional[bool] = None
26
30
  action: Optional[Literal["report", "block"]] = None
31
+ threshold: Optional[float] = None
27
32
 
28
33
 
29
34
  class LanguageDetectionOverride(APIRequestModel):
30
35
  disabled: Optional[bool] = None
31
- allow: Optional[list[str]] = None
32
- block: Optional[list[str]] = None
33
- report: Optional[list[str]] = None
36
+ action: Optional[Literal["", "report", "allow", "block"]] = ""
37
+ languages: Optional[list[str]] = None
38
+ threshold: Optional[float] = None
34
39
 
35
40
 
36
41
  class TopicDetectionOverride(APIRequestModel):
37
42
  disabled: Optional[bool] = None
38
- block: Optional[list[str]] = None
43
+ action: Optional[Literal["", "report", "block"]] = ""
44
+ topics: Optional[list[str]] = None
45
+ threshold: Optional[float] = None
39
46
 
40
47
 
41
48
  class PromptInjectionOverride(APIRequestModel):
@@ -138,6 +145,8 @@ class SecretsDetectionOverride(APIRequestModel):
138
145
 
139
146
 
140
147
  class Overrides(APIRequestModel):
148
+ """Overrides flags."""
149
+
141
150
  ignore_recipe: Optional[bool] = None
142
151
  """Bypass existing Recipe content and create an on-the-fly Recipe."""
143
152
 
@@ -152,7 +161,7 @@ class Overrides(APIRequestModel):
152
161
  secrets_detection: Optional[SecretsDetectionOverride] = None
153
162
  selfharm: Optional[SelfHarmOverride] = None
154
163
  sentiment: Optional[SentimentOverride] = None
155
- topic_detection: Optional[TopicDetectionOverride] = None
164
+ topic: Optional[TopicDetectionOverride] = None
156
165
 
157
166
 
158
167
  class LogFields(APIRequestModel):
@@ -242,15 +251,24 @@ class SecretsEntityResult(APIResponseModel):
242
251
 
243
252
 
244
253
  class LanguageDetectionResult(APIResponseModel):
245
- language: str
246
- action: str
254
+ action: Optional[str] = None
247
255
  """The action taken by this Detector"""
248
256
 
257
+ language: Optional[str] = None
258
+
259
+
260
+ class Topic(APIResponseModel):
261
+ topic: str
262
+ confidence: float
263
+
249
264
 
250
265
  class TopicDetectionResult(APIResponseModel):
251
- action: str
266
+ action: Optional[str] = None
252
267
  """The action taken by this Detector"""
253
268
 
269
+ topics: Optional[list[Topic]] = None
270
+ """List of topics detected"""
271
+
254
272
 
255
273
  class CodeDetectionResult(APIResponseModel):
256
274
  language: str
@@ -267,437 +285,49 @@ class TextGuardDetector(APIResponseModel, Generic[_T]):
267
285
 
268
286
 
269
287
  class TextGuardDetectors(APIResponseModel):
270
- prompt_injection: Optional[TextGuardDetector[PromptInjectionResult]] = None
271
- pii_entity: Optional[TextGuardDetector[PiiEntityResult]] = None
272
- malicious_entity: Optional[TextGuardDetector[MaliciousEntityResult]] = None
288
+ code_detection: Optional[TextGuardDetector[CodeDetectionResult]] = None
289
+ competitors: Optional[TextGuardDetector[object]] = None
273
290
  custom_entity: Optional[TextGuardDetector[object]] = None
274
- secrets_detection: Optional[TextGuardDetector[SecretsEntityResult]] = None
275
- profanity_and_toxicity: Optional[TextGuardDetector[object]] = None
291
+ gibberish: Optional[TextGuardDetector[object]] = None
292
+ hardening: Optional[TextGuardDetector[object]] = None
276
293
  language_detection: Optional[TextGuardDetector[LanguageDetectionResult]] = None
277
- topic_detection: Optional[TextGuardDetector[TopicDetectionResult]] = None
278
- code_detection: Optional[TextGuardDetector[CodeDetectionResult]] = None
294
+ malicious_entity: Optional[TextGuardDetector[MaliciousEntityResult]] = None
295
+ pii_entity: Optional[TextGuardDetector[PiiEntityResult]] = None
296
+ profanity_and_toxicity: Optional[TextGuardDetector[object]] = None
297
+ prompt_injection: Optional[TextGuardDetector[PromptInjectionResult]] = None
298
+ secrets_detection: Optional[TextGuardDetector[SecretsEntityResult]] = None
299
+ selfharm: Optional[TextGuardDetector[object]] = None
300
+ sentiment: Optional[TextGuardDetector[object]] = None
301
+ topic: Optional[TextGuardDetector[TopicDetectionResult]] = None
279
302
 
280
303
 
281
- class TextGuardResult(PangeaResponseResult, Generic[_T]):
304
+ class TextGuardResult(PangeaResponseResult):
282
305
  detectors: TextGuardDetectors
283
306
  """Result of the recipe analyzing and input prompt."""
284
307
 
285
- prompt_text: Optional[str] = None
286
- """Updated prompt text, if applicable."""
287
-
288
- prompt_messages: Optional[_T] = None
289
- """Updated structured prompt, if applicable."""
308
+ access_rules: Optional[object] = None
309
+ """Result of the recipe evaluating configured rules"""
290
310
 
291
- blocked: bool
311
+ blocked: Optional[bool] = None
292
312
  """Whether or not the prompt triggered a block detection."""
293
313
 
294
- recipe: str
295
- """The Recipe that was used."""
296
-
297
314
  fpe_context: Optional[str] = None
298
315
  """
299
- If an FPE redaction method returned results, this will be the context passed
300
- to unredact.
316
+ If an FPE redaction method returned results, this will be the context passed to
317
+ unredact.
301
318
  """
302
319
 
320
+ prompt_messages: Optional[object] = None
321
+ """Updated structured prompt, if applicable."""
303
322
 
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
- """
323
+ prompt_text: Optional[str] = None
324
+ """Updated prompt text, if applicable."""
690
325
 
326
+ recipe: Optional[str] = None
327
+ """The Recipe that was used."""
691
328
 
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
329
+ transformed: Optional[bool] = None
330
+ """Whether or not the original input was transformed."""
701
331
 
702
332
 
703
333
  class AIGuard(ServiceBase):
@@ -706,11 +336,9 @@ class AIGuard(ServiceBase):
706
336
  Provides methods to interact with Pangea's AI Guard service.
707
337
 
708
338
  Examples:
709
- from pangea import PangeaConfig
710
339
  from pangea.services import AIGuard
711
340
 
712
- config = PangeaConfig(domain="aws.us.pangea.cloud")
713
- ai_guard = AIGuard(token="pangea_token", config=config)
341
+ ai_guard = AIGuard(token="pangea_token")
714
342
  """
715
343
 
716
344
  service_name = "ai-guard"
@@ -730,11 +358,9 @@ class AIGuard(ServiceBase):
730
358
  config_id: Configuration ID.
731
359
 
732
360
  Examples:
733
- from pangea import PangeaConfig
734
361
  from pangea.services import AIGuard
735
362
 
736
- config = PangeaConfig(domain="aws.us.pangea.cloud")
737
- ai_guard = AIGuard(token="pangea_token", config=config)
363
+ ai_guard = AIGuard(token="pangea_token")
738
364
  """
739
365
 
740
366
  super().__init__(token, config, logger_name, config_id)
@@ -744,29 +370,31 @@ class AIGuard(ServiceBase):
744
370
  self,
745
371
  text: str,
746
372
  *,
747
- recipe: str | None = None,
748
373
  debug: bool | None = None,
749
- overrides: Overrides | None = None,
750
374
  log_fields: LogFields | None = None,
751
- ) -> PangeaResponse[TextGuardResult[None]]:
375
+ overrides: Overrides | None = None,
376
+ recipe: str | None = None,
377
+ ) -> PangeaResponse[TextGuardResult]:
752
378
  """
753
- Text Guard for scanning LLM inputs and outputs
379
+ Guard LLM input and output text
754
380
 
755
- Analyze and redact text to avoid manipulation of the model, addition of
756
- malicious content, and other undesirable data transfers.
381
+ Detect, remove, or block malicious content and intent in LLM inputs and
382
+ outputs to prevent model manipulation and data leakage.
757
383
 
758
384
  OperationId: ai_guard_post_v1_text_guard
759
385
 
760
386
  Args:
761
387
  text: Text to be scanned by AI Guard for PII, sensitive data,
762
388
  malicious content, and other data types defined by the
763
- configuration. Supports processing up to 10KB of text.
764
- recipe: Recipe key of a configuration of data types and settings
765
- defined in the Pangea User Console. It specifies the rules that
766
- are to be applied to the text, such as defang malicious URLs.
389
+ configuration. Supports processing up to 20 KiB of text.
767
390
  debug: Setting this value to true will provide a detailed analysis
768
391
  of the text data
769
392
  log_field: Additional fields to include in activity log
393
+ overrides: Overrides flags. Note: This parameter has no effect when
394
+ the request is made by AIDR
395
+ recipe: Recipe key of a configuration of data types and settings
396
+ defined in the Pangea User Console. It specifies the rules that
397
+ are to be applied to the text, such as defang malicious URLs.
770
398
 
771
399
  Examples:
772
400
  response = ai_guard.guard_text("text")
@@ -776,51 +404,53 @@ class AIGuard(ServiceBase):
776
404
  def guard_text(
777
405
  self,
778
406
  *,
779
- messages: _T,
407
+ messages: Sequence[Message],
780
408
  recipe: str | None = None,
781
409
  debug: bool | None = None,
782
410
  overrides: Overrides | None = None,
783
411
  log_fields: LogFields | None = None,
784
- ) -> PangeaResponse[TextGuardResult[_T]]:
412
+ ) -> PangeaResponse[TextGuardResult]:
785
413
  """
786
- Text Guard for scanning LLM inputs and outputs
414
+ Guard LLM input and output text
787
415
 
788
- Analyze and redact text to avoid manipulation of the model, addition of
789
- malicious content, and other undesirable data transfers.
416
+ Detect, remove, or block malicious content and intent in LLM inputs and
417
+ outputs to prevent model manipulation and data leakage.
790
418
 
791
419
  OperationId: ai_guard_post_v1_text_guard
792
420
 
793
421
  Args:
794
422
  messages: Structured messages data to be scanned by AI Guard for
795
423
  PII, sensitive data, malicious content, and other data types
796
- defined by the configuration. Supports processing up to 10KB of
797
- JSON text
798
- recipe: Recipe key of a configuration of data types and settings
799
- defined in the Pangea User Console. It specifies the rules that
800
- are to be applied to the text, such as defang malicious URLs.
424
+ defined by the configuration. Supports processing up to 20 KiB
425
+ of JSON text using Pangea message format.
801
426
  debug: Setting this value to true will provide a detailed analysis
802
427
  of the text data
803
428
  log_field: Additional fields to include in activity log
429
+ overrides: Overrides flags. Note: This parameter has no effect when
430
+ the request is made by AIDR
431
+ recipe: Recipe key of a configuration of data types and settings
432
+ defined in the Pangea User Console. It specifies the rules that
433
+ are to be applied to the text, such as defang malicious URLs.
804
434
 
805
435
  Examples:
806
- response = ai_guard.guard_text(messages=[{"role": "user", "content": "hello world"}])
436
+ response = ai_guard.guard_text(messages=[Message(role="user", content="hello world")])
807
437
  """
808
438
 
809
- def guard_text( # type: ignore[misc]
439
+ def guard_text(
810
440
  self,
811
441
  text: str | None = None,
812
442
  *,
813
- messages: _T | None = None,
814
- recipe: str | None = None,
443
+ messages: Sequence[Message] | None = None,
815
444
  debug: bool | None = None,
816
- overrides: Overrides | None = None,
817
445
  log_fields: LogFields | None = None,
818
- ) -> PangeaResponse[TextGuardResult[None]]:
446
+ overrides: Overrides | None = None,
447
+ recipe: str | None = None,
448
+ ) -> PangeaResponse[TextGuardResult]:
819
449
  """
820
- Text Guard for scanning LLM inputs and outputs
450
+ Guard LLM input and output text
821
451
 
822
- Analyze and redact text to avoid manipulation of the model, addition of
823
- malicious content, and other undesirable data transfers.
452
+ Detect, remove, or block malicious content and intent in LLM inputs and
453
+ outputs to prevent model manipulation and data leakage.
824
454
 
825
455
  OperationId: ai_guard_post_v1_text_guard
826
456
 
@@ -832,12 +462,14 @@ class AIGuard(ServiceBase):
832
462
  PII, sensitive data, malicious content, and other data types
833
463
  defined by the configuration. Supports processing up to 10KB of
834
464
  JSON text
835
- recipe: Recipe key of a configuration of data types and settings
836
- defined in the Pangea User Console. It specifies the rules that
837
- are to be applied to the text, such as defang malicious URLs.
838
465
  debug: Setting this value to true will provide a detailed analysis
839
466
  of the text data
840
467
  log_field: Additional fields to include in activity log
468
+ overrides: Overrides flags. Note: This parameter has no effect when
469
+ the request is made by AIDR
470
+ recipe: Recipe key of a configuration of data types and settings
471
+ defined in the Pangea User Console. It specifies the rules that
472
+ are to be applied to the text, such as defang malicious URLs.
841
473
 
842
474
  Examples:
843
475
  response = ai_guard.guard_text("text")
@@ -858,81 +490,3 @@ class AIGuard(ServiceBase):
858
490
  "log_fields": log_fields,
859
491
  },
860
492
  )
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
- )