From 77676d4a2ffd641396a26753817922a037ace1ee Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 3 Oct 2025 17:00:20 +0530 Subject: [PATCH] feat: stricter liquid rendering --- enterprise/app/models/concerns/toolable.rb | 6 +++++- enterprise/lib/captain/tools/http_tool.rb | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/enterprise/app/models/concerns/toolable.rb b/enterprise/app/models/concerns/toolable.rb index 89e1f4f2d..24c16c6f4 100644 --- a/enterprise/app/models/concerns/toolable.rb +++ b/enterprise/app/models/concerns/toolable.rb @@ -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) diff --git a/enterprise/lib/captain/tools/http_tool.rb b/enterprise/lib/captain/tools/http_tool.rb index 77132e3c1..b634de04e 100644 --- a/enterprise/lib/captain/tools/http_tool.rb +++ b/enterprise/lib/captain/tools/http_tool.rb @@ -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)