You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: product/guardrails.mdx
+304Lines changed: 304 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -330,6 +330,308 @@ Portkey will also show the feedback object logged for each request
330
330
331
331
---
332
332
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
## Understanding Guardrail Response Structure
341
+
342
+
When Guardrails are enabled and configured to run synchronously (`async=false`), Portkey adds a `hook_results` object to your API responses. This object provides detailed information about the guardrail checks that were performed and their outcomes.
343
+
344
+
### Hook Results Structure
345
+
346
+
The `hook_results` object contains two main sections:
347
+
348
+
```json
349
+
"hook_results": {
350
+
"before_request_hooks": [...], // Guardrails applied to the input
351
+
"after_request_hooks": [...] // Guardrails applied to the output
352
+
}
353
+
```
354
+
355
+
Each section contains an array of guardrail execution results, structured as follows:
356
+
357
+
<Expandabletitle="Hook Result Object Structure">
358
+
<ResponseFieldname="verdict"type="boolean">
359
+
Overall verdict of this guardrail (true = passed, false = failed). Only true if all checks within this guardrail passed.
360
+
</ResponseField>
361
+
<ResponseFieldname="id"type="string">
362
+
The ID of the guardrail that was executed (e.g., "pg-check-cfa540")
363
+
</ResponseField>
364
+
<ResponseFieldname="transformed"type="boolean">
365
+
Indicates if the guardrail modified the request or response (e.g., PII redaction)
366
+
</ResponseField>
367
+
<ResponseFieldname="checks"type="array">
368
+
An array of individual check results within this guardrail
369
+
<Expandabletitle="Check Object Structure">
370
+
<ResponseFieldname="data"type="object">
371
+
Check-specific data that varies based on the guardrail type (e.g., for wordCount it includes counts and thresholds)
372
+
</ResponseField>
373
+
<ResponseFieldname="verdict"type="boolean">
374
+
Result of this specific check (true = passed, false = failed)
375
+
</ResponseField>
376
+
<ResponseFieldname="id"type="string">
377
+
Identifier of the specific check (e.g., "default.sentenceCount", "default.wordCount")
378
+
</ResponseField>
379
+
<ResponseFieldname="execution_time"type="number">
380
+
Time taken to execute this check in milliseconds
381
+
</ResponseField>
382
+
<ResponseFieldname="transformed"type="boolean">
383
+
Whether this check modified the content
384
+
</ResponseField>
385
+
<ResponseFieldname="created_at"type="string">
386
+
Timestamp when the check was executed
387
+
</ResponseField>
388
+
<ResponseFieldname="log"type="string|null">
389
+
Additional logging information (if available)
390
+
</ResponseField>
391
+
<ResponseFieldname="error"type="string|object">
392
+
Error message or object if the guardrail encountered an error
393
+
</ResponseField>
394
+
</Expandable>
395
+
</ResponseField>
396
+
<ResponseFieldname="feedback"type="object">
397
+
Feedback information configured in the guardrail
398
+
<Expandabletitle="Feedback Object Structure">
399
+
<ResponseFieldname="value"type="number">
400
+
The numerical feedback value
401
+
</ResponseField>
402
+
<ResponseFieldname="weight"type="number">
403
+
The weight assigned to this feedback
404
+
</ResponseField>
405
+
<ResponseFieldname="metadata"type="object">
406
+
Additional metadata including which checks succeeded or failed
"sentence_and_word_check_guardrail"// The same guardrail can be used for both input and output
606
+
]
607
+
}
608
+
```
609
+
### Important Notes
610
+
611
+
- If a guardrail is configured to run asynchronously (`async=true`), the `hook_results` will not appear in the API response. The results will only be available in the Portkey logs.
612
+
- The `data` field varies based on the type of guardrail check being performed. Each guardrail type returns different information relevant to its function.
613
+
- The overall `verdict` for a guardrail is `true` only if all individual checks pass. If any check fails, the verdict will be `false`.
614
+
- When `transformed` is `true`, it indicates that the guardrail has modified the content (such as redacting PII).
615
+
- If `deny` is `true` and the verdict is `false`, the request will be denied with a 446 status code.
616
+
617
+
### Special Fields
618
+
619
+
-**Check-specific data**: Each guardrail type provides different data in the `data` field. For example, a sentence count check provides information about the number of sentences, while a PII check might provide information about detected PII entities.
620
+
-**Feedback metadata**: The `metadata` object within `feedback` keeps track of which checks were successful, failed, or encountered errors.
621
+
622
+
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+
632
+
633
+
634
+
333
635
## Defining Guardrails Directly in JSON
334
636
335
637
On Portkey, you can also create the Guardrails in code and add them to your Configs. Read more about this here:
@@ -338,6 +640,8 @@ On Portkey, you can also create the Guardrails in code and add them to your Conf
338
640
339
641
---
340
642
643
+
644
+
341
645
## Bring Your Own Guardrails
342
646
343
647
If you already have a custom guardrail pipeline where you send your inputs/outputs for evaluation, you can integrate it with Portkey using a modular, custom webhook! Read more here:
0 commit comments