Skip to main content

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:
Sequential Processing - Guardrails complete before LLM:

Context Manager Pattern

Use HaliosGuard 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

Pass TraceContext to control trace hierarchy and span relationships:

Advanced Span Control with Context Manager

Use HaliosGuard for fine-grained span management:

Trace Context Parameters

When creating TraceContext, 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 spans
  • span_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: