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: docs/quickstart.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,38 @@ asyncio.run(main())
81
81
82
82
**That's it!** Your existing OpenAI code now includes automatic guardrail validation based on your pipeline configuration. Just use `response.llm_response` instead of `response`.
83
83
84
+
## Multi-Turn Conversations
85
+
86
+
When maintaining conversation history across multiple turns, **only append messages after guardrails pass**. This prevents blocked input messages from polluting your conversation context.
87
+
88
+
```python
89
+
messages: list[dict] = []
90
+
91
+
whileTrue:
92
+
user_input =input("You: ")
93
+
94
+
try:
95
+
# ✅ Pass user input inline (don't mutate messages first)
# ❌ Guardrail blocked - message NOT added to history
110
+
print("Message blocked by guardrails")
111
+
continue
112
+
```
113
+
114
+
**Why this matters**: If you append the user message before the guardrail check, blocked messages remain in your conversation history and get sent on every subsequent turn, even though they violated your safety policies.
115
+
84
116
## Guardrail Execution Error Handling
85
117
86
118
Guardrails supports two error handling modes for guardrail execution failures:
0 commit comments