Module: Datadog::AIGuard::Evaluation
- Defined in:
- lib/datadog/ai_guard/evaluation.rb,
lib/datadog/ai_guard/evaluation/result.rb,
lib/datadog/ai_guard/evaluation/message.rb,
lib/datadog/ai_guard/evaluation/request.rb,
lib/datadog/ai_guard/evaluation/tool_call.rb,
lib/datadog/ai_guard/evaluation/no_op_result.rb
Overview
module that contains a function for performing AI Guard Evaluation request and creating ai_guard span with required tags
Defined Under Namespace
Classes: Message, NoOpResult, Request, Result, ToolCall
Class Method Summary collapse
Class Method Details
.perform(messages, allow_raise: false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/datadog/ai_guard/evaluation.rb', line 9 def perform(, allow_raise: false) raise ArgumentError, "Messages must not be empty" if &.empty? Tracing.trace(Ext::SPAN_NAME) do |span, trace| if ( = .last) if .tool_call span.set_tag(Ext::TARGET_TAG, "tool") span.set_tag(Ext::TOOL_NAME_TAG, .tool_call.tool_name) elsif .tool_call_id span.set_tag(Ext::TARGET_TAG, "tool") if ( = .find { |m| m.tool_call&.id == .tool_call_id }) span.set_tag(Ext::TOOL_NAME_TAG, .tool_call.tool_name) # steep:ignore end else span.set_tag(Ext::TARGET_TAG, "prompt") end end request = Request.new() result = request.perform span.set_tag(Ext::ACTION_TAG, result.action) span.set_tag(Ext::REASON_TAG, result.reason) span.( Ext::METASTRUCT_TAG, { messages: truncate_content(request.), attack_categories: result. } ) if allow_raise && (result.deny? || result.abort?) && result.blocking_enabled? span.set_tag(Ext::BLOCKED_TAG, true) raise AIGuardAbortError.new(action: result.action, reason: result.reason, tags: result.) end result end end |
.perform_no_op ⇒ Object
51 52 53 54 55 |
# File 'lib/datadog/ai_guard/evaluation.rb', line 51 def perform_no_op AIGuard.logger&.warn("AI Guard is disabled, messages were not evaluated") NoOpResult.new end |