-
Notifications
You must be signed in to change notification settings - Fork 2
Pre Tools
lacause edited this page Mar 29, 2026
·
3 revisions
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.
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: analysisPre-tools are not LLM calls — they run in-process and cost zero tokens (except web_search which uses Claude's built-in 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_resultsThe query field supports {variable} interpolation.
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 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 content to a file.
- type: write_file
path: "/tmp/output.json"
content: "{previous_step_output}"
inject_as: write_result- Supports
{variable}interpolation in bothpathandcontent - Creates parent directories if needed
- Returns "OK" on success
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
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
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
Control what happens when a pre-tool fails with the on_error field:
pre_tools:
- type: bash
command: "risky_command"
inject_as: data
on_error: skip # "inject" | "skip" | "fail"| Mode | Behavior |
|---|---|
inject (default) |
Injects [PRE-TOOL ERROR: message] into the prompt. Backwards-compatible. |
skip |
Injects empty string — step continues cleanly without error data. |
fail |
Aborts the entire step with an error. Use for critical pre-tools. |
Examples:
# Optional enrichment — don't block if it fails
- type: web_search
query: "latest news about {input.topic}"
inject_as: news
on_error: skip
# Critical data — abort if unavailable
- type: http_fetch
url: "https://api.internal.com/data"
inject_as: api_data
on_error: fail
# Default — error visible in prompt (LLM can adapt)
- type: bash
command: "git log --oneline -5"
inject_as: commits
# on_error: inject (default)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- Chain Format — Full YAML reference
- Step Types — How steps use pre-tool data
- Token Optimization — Pre-tools reduce LLM token usage