From 3bbe8f4b3de84ef131ab69a3e5191b562dc35e44 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Wed, 3 Jun 2026 14:22:31 -0600 Subject: [PATCH] docs: Added docs on the new LLM_TOOL_RAW_JSON escape hatch --- Custom-Bash-Tools.md | 54 ++++++++++++++++++++++++++++++++++++++++ Custom-Tools.md | 59 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 107 insertions(+), 6 deletions(-) diff --git a/Custom-Bash-Tools.md b/Custom-Bash-Tools.md index b138d81..a8d29fc 100644 --- a/Custom-Bash-Tools.md +++ b/Custom-Bash-Tools.md @@ -284,6 +284,60 @@ $ ./get_current_time.sh Fri Oct 24 05:55:04 PM MDT 2025 ``` +# Handling large or special-character argument values + +Coyote dispatches a tool call by converting the LLM's JSON arguments into shell `--option=` flags via `jq`, then +`eval`-ing the result. The flag values reach your `main` function as `argc_*` variables. For most calls this works fine. + +However, for **very large values, multi-line values dense with newlines, or values with many markdown table pipes (`|`), +single quotes, em-dashes, and other shell-significant characters**, the shell-quoting round-trip can occasionally drop +characters or truncate the value before it reaches your `argc_*` variable. Symptoms include `argc_*` being shorter than +what the LLM sent, or starting mid-content. + +## The escape hatch: `LLM_TOOL_RAW_JSON` + +Coyote exports the raw JSON envelope it received from the LLM as the `LLM_TOOL_RAW_JSON` environment variable on every +tool invocation. To bypass argc parsing for a specific option, re-derive its value directly from the JSON using `jq`: + +```bash +# Prefer the raw JSON when available, fall back to argc parsing if not +if [[ -n "$LLM_TOOL_RAW_JSON" ]] && command -v jq >/dev/null 2>&1; then + argc_contents="$(jq -r '.contents' <<< "$LLM_TOOL_RAW_JSON")" + argc_path="$(jq -r '.path' <<< "$LLM_TOOL_RAW_JSON")" +fi +``` + +The `jq -r` ("raw") flag preserves every byte of the original LLM-sent value, including newlines, quotes, em-dashes, +and shell-special characters, without any shell-quoting layer in between. This is the same approach Coyote's bundled +`fs_write`, `fs_patch`, `execute_command`, `execute_sql_code`, and `send_mail` tools use for their large-payload options. + +The fallback (`fall back to argc parsing if not`) is intentional: if `LLM_TOOL_RAW_JSON` is unset or `jq` isn't +installed, the tool still works via the standard argc path. You're adding a more reliable code path, not replacing the +existing one. + +## When to use this + +- Your option's value can legitimately be many KB of text (file contents, code, email bodies, SQL queries). +- Your option's value can contain shell-significant characters in dense patterns (pipes, single quotes, ANSI escapes). +- You observe that `argc_