This page is for version v0.25.0.
For other versions, use one of these documentation indexes:
- Latest (default): https://docs.nvidia.com/nemo/guardrails/latest/llms.txt
- v0.25.0: https://docs.nvidia.com/nemo/guardrails/v0.25.0/llms.txt
- v0.24.1: https://docs.nvidia.com/nemo/guardrails/v0.24.1/llms.txt
- v0.24.0: https://docs.nvidia.com/nemo/guardrails/v0.24.0/llms.txt
- v0.23.0: https://docs.nvidia.com/nemo/guardrails/v0.23.0/llms.txt
- v0.22.0: https://docs.nvidia.com/nemo/guardrails/v0.22.0/llms.txt
The following is a minimal setup to enable tracing using the OpenTelemetry SDK.
-
Install the NeMo Guardrails library and the OpenTelemetry SDK.
pip install nemoguardrails[tracing] opentelemetry-sdk -
Set up tracing as follows and save as
trace_example.py.# trace_example.pyfrom opentelemetry import tracefrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporterfrom opentelemetry.sdk.resources import Resourcefrom nemoguardrails import LLMRails, RailsConfig# Configure OpenTelemetryresource = Resource.create({"service.name": "guardrails-quickstart"})tracer_provider = TracerProvider(resource=resource)trace.set_tracer_provider(tracer_provider)tracer_provider.add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))# Configure guardrails with tracingconfig_yaml = """models:- type: mainengine: openaimodel: gpt-4o-minirails:config:streaming: truetracing:enabled: trueadapters:- name: OpenTelemetry"""config = RailsConfig.from_content(yaml_content=config_yaml)rails = LLMRails(config)response = rails.generate(messages=[{"role": "user", "content": "Hello!"}])print(f"Response: {response}") -
Run the script:
python trace_example.py