Table of Contents
When using Raif to interact with the LLM, you can specify the response format you want to receive. The response format will be one of text
, json
, or html
.
You can specify the response format when chatting directly with the LLM, or when creating a Task or Conversation.
JSON Response Format
When using the json
response format, Raif will:
- Strip any markdown code fences inserted by the LLM
- Parse the response as JSON.
If you’re using the OpenAI adapter, Raif will automatically enable OpenAI’s JSON mode feature.
And if you define a JSON schema, it will trigger utilization of OpenAI’s structured outputs feature, which will force the response to adhere to your schema.
HTML Response Format
When using the html
response format, Raif will:
- Strip any markdown code fences inserted by the LLM
- Convert markdown links to HTML links.
- Strip
utm_
tracking parameters from URLs. - Sanitize the HTML using Rails’
sanitize
method.
By default, Raif will use Rails::HTML5::SafeListSanitizer.allowed_tags
and Rails::HTML5::SafeListSanitizer.allowed_attributes
.
You can override these using the llm_response_allowed_tags
and llm_response_allowed_tags
class methods. See the Raif::Tasks::DocumentSummarization
example task for usage.
Read next: Streaming Responses