Skip to main content
This page documents the enrichment schema - available namespaces, supported data types, and how they map to backend attributes. For how to use enrichment functions, see Enriching Traces.

Available Namespaces

Enrichments are key-value pairs that add context to your traces. Both enrich_span() and enrich_session() support these namespaces:
Setting event type: To set the event type (chain, model, tool), use the @trace decorator’s event_type parameter, not enrichment functions. Example: @trace(event_type="model").

Backend Attributes

Each namespace maps to a specific backend attribute prefix:
Additive behavior: For Object-type enrichments (config, metadata, etc.), enrichments are additive for unique keys. Enriching the same field twice with different keys includes both. Enriching the same key twice overwrites the previous value.

Parameter Precedence

When using enrich_span() with mixed invocation patterns (dict, kwargs, namespaces), parameters are merged in this order:
  1. Reserved namespaces (metadata, metrics, etc.) - Applied first
  2. attributes dict (simple dict passed as first argument) - Applied second
  3. **kwargs (keyword arguments) - Applied last, wins conflicts
Kwargs override dict values when the same key appears in both. Use explicit namespaces (metadata=, metrics=) for clarity.

Supported Data Types

You can enrich with these data types:
Complex objects (lists, nested dicts) are automatically serialized to JSON strings for storage.

Nesting Limits

For complex data types:
  • Objects: Maximum 5 levels of nesting
  • Arrays: Maximum 2 levels of nesting
When querying nested data in the dashboard, use dot notation:
You can chart:
  • metrics.step_evals.0.user_intervened (boolean)
  • metrics.trajectory_eval.overall (number)

Best Practices

DO:
  • Use consistent key names across your application
  • Add user/session IDs for debugging
  • Include feature/endpoint identifiers
  • Use descriptive key names (user_id not uid)
  • Keep values under 1KB per field
DON’T:
  • Include sensitive data (passwords, API keys, PII)
  • Use random or generated key names
  • Duplicate data already captured by auto-instrumentors
  • Exceed nesting limits (5 objects, 2 arrays)

Task-Specific Guides

Each namespace has a dedicated guide with detailed examples:

Metrics & Evaluations

The metrics namespace for scores and evaluations

User Feedback

The feedback namespace for ratings and comments

Prompts

Manage prompt templates and model configs

User Properties

The user_properties namespace for user context

Custom Metadata

The metadata namespace for arbitrary data

SDK Reference