Class: Datadog::AIGuard::Contrib::RubyLLM::RedactionChangeSet Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ai_guard/contrib/ruby_llm/redaction_change_set.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Changes required to redact a RubyLLM message

Instance Method Summary collapse

Constructor Details

#initialize(original_message, redacted_message) ⇒ RedactionChangeSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RedactionChangeSet.



14
15
16
17
18
# File 'lib/datadog/ai_guard/contrib/ruby_llm/redaction_change_set.rb', line 14

def initialize(original_message, redacted_message)
  @content_replacement = content_replacement(original_message.content, redacted_message.content)
  @content_part_replacements = content_part_replacements(original_message.content, redacted_message.content)
  @tool_call_replacements = tool_call_replacements(original_message.tool_calls, redacted_message.tool_calls)
end

Instance Method Details

#apply_to(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/datadog/ai_guard/contrib/ruby_llm/redaction_change_set.rb', line 20

def apply_to(message)
  return message unless changed?

  # NOTE: Preserve `raw_content` after provider-specific redaction is implemented.
  #       Unchanged raw content could bypass redaction
  if message.raw_content
    Datadog.logger.warn("AI Guard omitted RubyLLM raw content because it may contain sensitive data")
  end

  content = build_content(message)
  attachments = build_attachments(message)
  tool_calls = build_tool_calls(message)

  changed_message = ::RubyLLM::Message.new(
    content: content, attachments: attachments, tool_calls: tool_calls,
    role: message.role, model: message.model, tool_call_id: message.tool_call_id,
    raw: message.raw, thinking: message.thinking, citations: message.citations,
    finish_reason: message.finish_reason, server_tool_calls: message.server_tool_calls,
    raw_reasoning: message.raw_reasoning, cache_until_here: message.cache_until_here?,
  )
  changed_message.conversation = message.conversation
  changed_message
end