Skip to content
mentoor

Topic 5 of 5 · 5 min read

Inspecting the requests a framework sends

Goal: Read a framework's raw request log and identify the hidden instruction or retry that explains an unexpected behaviour.

When an agent surprises you, read the exact requests that went to the model, because the framework may have added text, tools or retries you never wrote. The final request is the truth. Your code is only a description of it.

Check yourself · 1 of 3

Why log the raw request a framework sends?

Choose one answer

Why look

A framework builds each request from your instructions plus its own: default system text, formatting rules for tool calls, the schemas it generated from your function signatures, a summary of earlier turns, and sometimes extra tools. It may also retry a failed call or re-ask the model after a validation error. None of that shows in your source.

How to capture the requests

Choose the lowest layer you can reach:

  1. The framework's tracing. Most SDKs ship tracing or a debug flag. Turn it on and read the full inputs and outputs, not only the summary.
  2. The provider SDK's logging. Many client libraries print requests when you set a log level.
  3. A logging HTTP proxy. Point the client's base URL at a local proxy that writes every request and response to a file. This works for any framework because it sits below it.
  4. A wrapper around the model call. In your own gateway, write the request and reply to a file.

Redact secrets and personal data from logs, and keep logs from production access-controlled.

What to read in a request

  • The system prompt: is there text you did not write?
  • The tool list: are the names and descriptions what you expect, and are there extra tools?
  • The message history: is an old tool result huge, truncated or missing?
  • The parameters: model id, temperature, token limit.
  • The count of calls per user turn: more than one means a retry or a loop.

Before and after

Weak debugging: "The agent keeps answering in a formal tone. I will rewrite my prompt again." Three rewrites change nothing.

Better: log the request. The system message ends with a framework default that says "Always respond in a professional tone." Your prompt was fine. Override that default, or move to a lower-level call.

What goes wrong

  • Reading only the trace summary. It may show tool names but not the prompt text.
  • Logging secrets. Request logs contain customer data and sometimes keys.
  • Fixing the wrong layer. Editing your prompt when the cause is a retry or a truncated history.
  • Debugging a different version. Upgrading the framework changes the hidden text, so log again after each upgrade.

Examples

The hidden instruction

{
  "model": "example-model",
  "messages": [
    {"role": "system", "content": "You are a refund assistant. Be brief.\n\nAlways respond in a professional tone. If unsure, ask the user a clarifying question."},
    {"role": "user", "content": "Refund order 4417"}
  ]
}

The developer wrote only "You are a refund assistant. Be brief." The second paragraph comes from the framework. It explains why the agent keeps asking clarifying questions even when the order id is clear.

Three calls, one question

A user asks one question and the log shows three requests. The second contains the text "Your last output failed validation: field amount must be a number." The framework validated the structured output, failed, and silently asked again. The retry doubled the cost of that turn. The fix is a clearer schema description, not a longer prompt.

Key points

  • The request on the wire is the truth: it includes framework text, generated tool schemas, retries and trimmed history.
  • Capture requests with the framework's tracing, the provider SDK's logging, a local HTTP proxy or your own gateway wrapper.
  • Read the system prompt, tool list, message history, parameters and the number of model calls per user turn.
  • Several model calls for one user turn point to a retry, a validation loop or an agent loop.
  • Redact secrets and personal data from logs and log again after every framework upgrade.

Common mistakes

  • Rewriting prompts repeatedly without looking at the request that was sent.
  • Trusting a trace summary that hides the full system prompt.
  • Leaving customer data and keys in debug logs.
  • Keeping old conclusions after a framework upgrade changed its defaults.

Check yourself · 2 of 3

One user question produces three model requests in the log. What is the most likely explanation?

Choose one answer

Check yourself · 3 of 3

A raw request log contains a system sentence you never wrote. Where did it most likely come from?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic