class RubyLLM::ContentFilter
A ContentFilter is one verdict of the provider’s content filtering on a request or its response, such as Azure’s hate or protected material filters. They appear on Message#content_filters for providers that report them, whether or not they stopped the response, so you can see why a reply ended with Message#content_filtered? or what came close.
response = chat.ask "Summarize this paper" response.content_filtered? # => true response.content_filters.select(&:filtered?).map(&:category) # => ["hate"]
A verdict names a category and a severity, never the text it judged.
Attributes
The provider’s name for the category, such as "hate", "jailbreak", or "protected_material_text".
The severity the provider gave, such as "safe", "low", or "medium", or nil for a category judged only as detected or not.
Which side was judged: :prompt for the request, :completion for the response.
Public Instance Methods
Source
# File lib/ruby_llm/content_filter.rb, line 55 def detected? @detected end
Returns whether the provider detected what the category looks for, such as a jailbreak attempt or protected material, or nil for a category judged by severity.
Source
# File lib/ruby_llm/content_filter.rb, line 48 def filtered? @filtered end
Returns whether the filter blocked or cut the text it judged.
Source
# File lib/ruby_llm/content_filter.rb, line 60 def to_h { source: source, category: category, severity: severity, filtered: filtered?, detected: @detected }.compact end
Returns the verdict as a Hash, omitting nil values.