2. Install the SDK
Decorator Pattern
Use the@guarded_chat_completion decorator for automatic guardrail evaluation:
Processing Modes
Parallel Processing (Default) - Guardrails run concurrently with LLM:Context Manager Pattern
UseHaliosGuard for manual control over guardrail evaluation:
Key Features
- Flexible Processing: Parallel (faster) or sequential (safer) modes
- Async Support: Full asyncio compatibility with OpenAI client
- Minimal Changes: Decorator requires almost no code modification
- Manual Control: Context manager gives full evaluation control
- Error Handling: Comprehensive error management and logging
Trace Context and Span Management
The SDK supports distributed tracing with automatic span creation and propagation. You can pass explicit trace context for observability or let the SDK create it automatically.Automatic Trace Creation (Default)
If no trace context is provided, the SDK automatically creates traces and spans:Explicit Trace Context
PassTraceContext to control trace hierarchy and span relationships:
Advanced Span Control with Context Manager
UseHaliosGuard for fine-grained span management:
Trace Context Parameters
When creatingTraceContext, you can specify:
trace_id: Custom 32-character hex string for the trace (auto-generated if not provided)conversation_id: Human-readable identifier for grouping related spansspan_id: Custom span identifier (auto-generated if not provided)parent_span_id: Parent span ID for hierarchical relationships (auto-generated if not provided)
When to Use Explicit Trace Context
- Multi-turn conversations: Maintain trace continuity across turns
- Distributed systems: Propagate traces across service boundaries
- Custom observability: Control span naming and hierarchy
- Debugging: Correlate logs and metrics with specific operations
Examples
See the SDK examples for different implementation patterns:- Basic Usage - Decorator patterns and processing modes
- Context Manager - Manual evaluation control
- Streaming Response - Evaluate guardrails on streaming response
- Tool Calling - Guardrail evaluation with tool calling
- Validating Tool Input & Output - Evaluate guardrails on tool output
- Traces and Spans - Trace context and span management

