Skip to content

Pre Tools

lacause edited this page Mar 29, 2026 · 3 revisions

Pre-Tools

Pre-tools inject data into a step's prompt before the LLM runs. They execute in order and make their results available as {inject_as} variables.

Overview

steps:
  - id: my_step
    pre_tools:
      - type: web_search
        query: "AI trends 2026"
        inject_as: trends

      - type: current_datetime
        inject_as: now

    prompt: |
      Current date: {now}
      Trends data: {trends}

      Analyze the above trends.
    output_var: analysis

Pre-tools are not LLM calls — they run in-process and cost zero tokens (except web_search which uses Claude's built-in search).

Available Pre-Tools

web_search

Search the web using Claude's built-in web search tool.

- type: web_search
  query: "latest {input.topic} research papers 2026"
  inject_as: search_results

The query field supports {variable} interpolation.

http_fetch

Fetch data from any URL.

- type: http_fetch
  url: "https://api.example.com/data?q={input.query}"
  inject_as: api_data
  • Supports {variable} interpolation in the URL
  • Response truncated to 50KB
  • Timeout: 30 seconds
  • Returns response body as text

read_file

Read a file from disk.

- type: read_file
  path: "/path/to/context.md"
  inject_as: context
  • Supports {variable} interpolation in the path
  • Returns file contents as UTF-8 text

write_file

Write content to a file.

- type: write_file
  path: "/tmp/output.json"
  content: "{previous_step_output}"
  inject_as: write_result
  • Supports {variable} interpolation in both path and content
  • Creates parent directories if needed
  • Returns "OK" on success

bash

Execute a shell command.

- type: bash
  command: "git log --oneline -5"
  inject_as: recent_commits
  • Supports {variable} interpolation in the command
  • Timeout: 30 seconds
  • Max output: 10MB
  • Returns stdout as text

env_var

Read an environment variable.

- type: env_var
  var_name: "API_KEY"
  inject_as: key
  • Returns the value of the environment variable
  • Returns empty string if not set

current_datetime

Get the current date and time.

- type: current_datetime
  inject_as: now
  • Returns ISO 8601 format: 2026-03-29T14:30:00.000Z
  • Useful for time-aware prompts

Error Handling

If a pre-tool fails, the error is injected as the variable value:

[PRE-TOOL ERROR: command not found]

The step continues with this error string in the prompt. Design your prompts to handle this gracefully, or use condition to skip steps when pre-tools fail.

Multiple Pre-Tools

Pre-tools execute in order. Later pre-tools can reference results from earlier ones:

pre_tools:
  - type: bash
    command: "cat package.json"
    inject_as: pkg

  - type: bash
    command: "echo {pkg} | jq '.dependencies | keys[]'"
    inject_as: deps

See Also

Clone this wiki locally