Skip to content

feat(ruby_llm): capture prompt, completion, and tool I/O when capture_bodies is enabled - #2

Merged
TonsOfFun merged 2 commits into
mainfrom
release/0.2.0
Aug 14, 2026
Merged

feat(ruby_llm): capture prompt, completion, and tool I/O when capture_bodies is enabled#2
TonsOfFun merged 2 commits into
mainfrom
release/0.2.0

Conversation

@TonsOfFun

Copy link
Copy Markdown
Contributor

The capture_bodies flag existed but the RubyLLM adapter never read it, so every trace recorded only shape: spans, tokens, cost, latency. A trace could show that a turn called a tool and what it cost, but not what was asked, what came back, or what the tool returned — which is most of what makes a trace worth reading when a turn goes wrong.

This implements the flag and releases it as 0.2.0.

What is captured

With capture_bodies enabled, the root span carries llm.prompt, llm.instructions and llm.completion, and each tool span carries tool.arguments and tool.result. Each value is truncated to 4,000 characters (RubyLLM::CONTENT_LIMIT).

Two details worth calling out:

  • llm.instructions joins every system message. RubyLLM's with_instructions appends by default, so a chat can carry several; reporting only the last would hide a layered base prompt and misrepresent what the model actually saw.
  • A tool span records a result only when the call succeeded. A raised tool reports its truncated error message instead, via the existing record_error path.

Capture stays off by default

Prompts and tool results carry whatever the application sends the model, so enabling this is a data-handling decision for the app, not a default. Worth being explicit that the 4,000-character limit is a cap on trace size, not a redaction boundary — a tool result naming a person still names them within its first 4,000 characters.

Verification

13 runs, 41 assertions, 0 failures, including two new cases: one asserting that nothing is captured by default, and one asserting the full attribute set, the joined instructions, and the truncation limit when the flag is on.

Also exercised end to end from a Rails app against a live dashboard: with the flag set, all five attributes arrive populated and the tool result truncates at exactly 4,000 characters; with it unset, traces still deliver with every one of those keys absent.

@TonsOfFun
TonsOfFun marked this pull request as ready for review August 14, 2026 20:45
@TonsOfFun
TonsOfFun merged commit 47447b6 into main Aug 14, 2026
6 checks passed
@TonsOfFun
TonsOfFun deleted the release/0.2.0 branch August 14, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant