Skip to content

Commit 46a69bc

Browse files
authored
docs: document updates for #687 runInParallel option for input guardrails (#688)
1 parent 9d10083 commit 46a69bc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

docs/src/content/docs/guides/guardrails.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Code } from '@astrojs/starlight/components';
77
import inputGuardrailExample from '../../../../../examples/docs/guardrails/guardrails-input.ts?raw';
88
import outputGuardrailExample from '../../../../../examples/docs/guardrails/guardrails-output.ts?raw';
99

10-
Guardrails run _in parallel_ to your agents, allowing you to perform checks and validations on user input or agent output. For example, you may run a lightweight model as a guardrail before invoking an expensive model. If the guardrail detects malicious usage, it can trigger an error and stop the costly model from running.
10+
Guardrails can run alongside your agents or block execution until they complete, allowing you to perform checks and validations on user input or agent output. For example, you may run a lightweight model as a guardrail before invoking an expensive model. If the guardrail detects malicious usage, it can trigger an error and stop the costly model from running.
1111

1212
There are two kinds of guardrails:
1313

@@ -25,6 +25,11 @@ Input guardrails run in three steps:
2525
> **Note**
2626
> Input guardrails are intended for user input, so they only run if the agent is the _first_ agent in the workflow. Guardrails are configured on the agent itself because different agents often require different guardrails.
2727
28+
### Execution modes
29+
30+
- `runInParallel: true` (default) starts guardrails alongside the LLM/tool calls. This minimizes latency but the model may already have consumed tokens or run tools if the guardrail later triggers.
31+
- `runInParallel: false` runs the guardrail **before** calling the model, preventing token spend and tool execution when the guardrail blocks the request. Use this when you prefer safety and cost over latency.
32+
2833
## Output guardrails
2934

3035
Output guardrails run in 3 steps:

examples/docs/guardrails/guardrails-input.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const guardrailAgent = new Agent({
1717

1818
const mathGuardrail: InputGuardrail = {
1919
name: 'Math Homework Guardrail',
20+
// Set runInParallel to false to block the model until the guardrail completes.
21+
runInParallel: false,
2022
execute: async ({ input, context }) => {
2123
const result = await run(guardrailAgent, input, { context });
2224
return {

0 commit comments

Comments
 (0)