apply_guardrail_scope Module

OpenTelemetry tracing scope for guardrail (security guardian) evaluations.

Classes

ApplyGuardrailScope

Provides OpenTelemetry tracing scope for security guardrail evaluations.

Guardian spans SHOULD be children of the operation span they are protecting (e.g., inference or execute_tool spans). Multiple guardian spans MAY exist under a single operation span if multiple guardians are chained.

Example usage:


   from microsoft.opentelemetry.a365.core import (
       ApplyGuardrailScope, GuardrailDetails, AgentDetails,
       GuardrailDecisionType, GuardrailTargetType, GuardrailRiskSeverity,
       GuardrailFinding,
   )

   details = GuardrailDetails(
       target_type=GuardrailTargetType.LLM_INPUT,
       decision_type=GuardrailDecisionType.ALLOW,
       guardian_name="Azure Content Safety",
   )

   with ApplyGuardrailScope.start(details, agent_details) as scope:
       # ... run guardrail evaluation ...
       scope.record_finding(GuardrailFinding(
           risk_category="hate_speech",
           risk_severity=GuardrailRiskSeverity.HIGH,
           risk_score=0.95,
       ))
       scope.record_decision(GuardrailDecisionType.DENY, "Blocked by policy")

Initialize the guardrail scope.