feat: stricter liquid rendering

This commit is contained in:
Shivam Mishra
2025-10-03 17:02:01 +05:30
parent 03af966d87
commit 77676d4a2f
2 changed files with 8 additions and 2 deletions
+5 -1
View File
@@ -63,7 +63,11 @@ module Concerns::Toolable
private
def render_template(template, context)
Liquid::Template.parse(template).render(context.deep_stringify_keys)
liquid_template = Liquid::Template.parse(template, error_mode: :strict)
liquid_template.render(context.deep_stringify_keys, registers: {}, strict_variables: true, strict_filters: true)
rescue Liquid::SyntaxError, Liquid::UndefinedVariable, Liquid::UndefinedFilter => e
Rails.logger.error("Liquid template error: #{e.message}")
raise "Template rendering failed: #{e.message}"
end
def parse_response_body(body)
+3 -1
View File
@@ -35,7 +35,9 @@ class Captain::Tools::HttpTool < Agents::Tool
IPAddr.new('fe80::/10') # IPv6 Link-local
].freeze
MAX_RESPONSE_SIZE = 2.megabytes
# Limit response size to prevent memory exhaustion and match LLM token limits
# 1MB of text ≈ 250K tokens, which exceeds most LLM context windows
MAX_RESPONSE_SIZE = 1.megabyte
def execute_http_request(url, body)
uri = URI.parse(url)