Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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月29日T14:30:00.000Z
  • Useful for time-aware prompts

Error Handling (on_error)

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)

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

AltStyle によって変換されたページ (->オリジナル) /