aidputils.agents.tools.http.template_engine

Template Engine for HTTP Tool.

Provides secure template variable substitution with: - {{variable}} syntax resolution - URL encoding for template values - Path traversal prevention - Character validation (reject control chars, newlines) - Length validation

exception aidputils.agents.tools.http.template_engine.TemplateError[source]

Bases: ValueError

Exception raised for template-related errors.

exception aidputils.agents.tools.http.template_engine.SecurityError[source]

Bases: ValueError

Exception raised for security-related validation failures.

aidputils.agents.tools.http.template_engine.validate_template_value(value: str, context: str = 'value') None[source]

Validate a template value for security issues.

Parameters:
  • value – The value to validate

  • context – Description of where this value is used (for error messages)

Raises:

SecurityError – If the value contains dangerous patterns

aidputils.agents.tools.http.template_engine.url_encode_value(value: str) str[source]

URL-encode a template value for safe inclusion in URLs.

Parameters:

value – The value to encode

Returns:

URL-encoded value

aidputils.agents.tools.http.template_engine.substitute_template(value: Any, runtime_params: Dict[str, Any], url_encode: bool = False, validate_security: bool = True) Any[source]

Recursively substitute {{variable}} placeholders in a value.

Parameters:
  • value – String, dict, list, or other value to process

  • runtime_params – Dictionary of variable name -> value mappings

  • url_encode – Whether to URL-encode substituted values

  • validate_security – Whether to validate values for security issues

Returns:

Value with all {{variable}} placeholders substituted

Raises:
aidputils.agents.tools.http.template_engine.substitute_url(url_template: str, runtime_params: Dict[str, Any]) str[source]

Substitute template variables in a URL with security validation.

Template values are URL-encoded and validated for path traversal.

Parameters:
  • url_template – URL with {{variable}} placeholders

  • runtime_params – Dictionary of variable name -> value mappings

Returns:

URL with all placeholders substituted

Raises:
aidputils.agents.tools.http.template_engine.substitute_headers(headers: Dict[str, str], runtime_params: Dict[str, Any]) Dict[str, str][source]

Substitute template variables in headers with security validation.

Parameters:
  • headers – Dictionary of header name -> value (with possible templates)

  • runtime_params – Dictionary of variable name -> value mappings

Returns:

Headers with all placeholders substituted

Raises:
aidputils.agents.tools.http.template_engine.substitute_body(body: Any, runtime_params: Dict[str, Any]) Any[source]

Substitute template variables in request body.

Parameters:
  • body – Request body (dict, list, or string) with possible templates

  • runtime_params – Dictionary of variable name -> value mappings

Returns:

Body with all placeholders substituted

Raises:

TemplateError – If a variable is missing