Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/langchain-debug-bundle

@0d57af8
Run it yourself

Produce a reproducible, sanitized diagnostic bundle for a LangChain / LangGraph incident — environment snapshot, version manifest, filtered astream_events(v2) transcript, propagating callback stack, LangSmith trace URL — so a debug colleague can reproduce the failure without a live terminal. Use when triaging a production incident, filing a Discord or GitHub bug report, asking for help on the LangChain forum, or archiving a post-mortem artifact. Trigger with "langchain debug bundle", "langgraph debug dump", "langchain diagnostic export", "langsmith trace export", "astream_events dump", "langchain incident bundle".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/langchain-debug-bundle

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescallback-propagation.md

≈1.7k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Callback Propagation into Subgraphs

This is the single most common reason a debug bundle comes back empty from the inside of a LangGraph agent: the DebugCallbackHandler fires on the outer chain, then goes silent the moment the graph crosses into a subgraph, create_react_agent inner loop, or a tool-executed sub-chain.

Pain-catalog anchor: P28 — custom callbacks are not inherited by subgraphs.

The rule in one sentence

Pass callbacks via config["callbacks"] at invocation time. Do not bind them via Runnable.with_config(callbacks=[...]) at definition time.

Why

LangGraph creates a child runtime per subgraph. Configuration passed at invoke time propagates down through the RunnableConfig that is threaded through every node call. Configuration bound at definition time is attached to the parent Runnable only — the child runtime builds its own config from scratch.

A concise way to hold it: definition-time config is for the node's own execution; invoke-time config is for the whole tree below it.

Wrong vs right

Wrong — callback binds at definition; fires only on outer chain

from langchain_core.callbacks import BaseCallbackHandler

class DebugCallback(BaseCallbackHandler):
    def __init__(self, out):
        self.out = out
    def on_tool_start(self, *a, **kw): self.out.append(("tool_start", a, kw))

debug = DebugCallback(out=[])

# DO NOT DO THIS for diagnostics
agent = create_react_agent(model, tools).with_config(callbacks=[debug])
# agent.invoke(...)  # debug.out captures outer events only; inner tool calls silent

Right — callback passed at invoke; propagates everywhere

agent = create_react_agent(model, tools)

debug = DebugCallback(out=[])
result = agent.invoke(
    {"messages": [("user", "...")]},
    config={
        "configurable": {"thread_id": "t-1"},
        "callbacks": [debug],                # <-- propagates into subgraphs
        "max_concurrency": 5,
    },
)
# debug.out now contains events from every node, every tool, every inner subgraph

Same rule applies to ainvoke, stream, astream, and astream_events.

DebugCallbackHandler — a minimal capture

A bundle-friendly callback records just enough to reconstruct what happened, without loading the process memory with every token:

from langchain_core.callbacks import BaseCallbackHandler
import time, json

class DebugCallbackHandler(BaseCallbackHandler):
    """Records tool calls, LLM start/end, and errors.

    Deliberately DOES NOT record per-token stream chunks — that is the job of
    the astream_events JSONL capture. Callbacks are for coarse-grained stack
    context; events are for fine-grained traces.
    """

    def __init__(self) -> None:
        self.records: list[dict] = []
        self._start: dict[str, float] = {}

    def _ts(self) -> float:
        return time.monotonic()

    def on_chat_model_start(self, serialized, messages, *, run_id, parent_run_id=None, **kw):
        self._start[str(run_id)] = self._ts()
        self.records.append({
            "kind": "llm_start",
            "run_id": str(run_id),
            "parent_run_id": str(parent_run_id) if parent_run_id else None,
            "model": serialized.get("kwargs", {}).get("model"),
            "message_count": len(messages[0]) if messages else 0,
        })

    def on_llm_end(self, response, *, run_id, **kw):
        dt = self._ts() - self._start.pop(str(run_id), self._ts())
        usage = {}
        for gen in response.generations:
            for g in gen:
                meta = getattr(g.message, "usage_metadata", None) or {}
                usage = meta
        self.records.append({
            "kind": "llm_end",
            "run_id": str(run_id),
            "duration_ms": int(dt * 1000),
            "usage_metadata": usage,
        })

    def on_tool_start(self, serialized, input_str, *, run_id, parent_run_id=None, **kw):
        self._start[str(run_id)] = self._ts()
        self.records.append({
            "kind": "tool_start",
            "run_id": str(run_id),
            "parent_run_id": str(parent_run_id) if parent_run_id else None,
            "tool": serialized.get("name"),
            "input": input_str[:500],   # cap payload; full input lives in events.jsonl
        })

    def on_tool_end(self, output, *, run_id, **kw):
        dt = self._ts() - self._start.pop(str(run_id), self._ts())
        self.records.append({
            "kind": "tool_end",
            "run_id": str(run_id),
            "duration_ms": int(dt * 1000),
            "output_snippet": str(output)[:500],
        })

    def on_tool_error(self, error, *, run_id, **kw):
        self.records.append({
            "kind": "tool_error",
            "run_id": str(run_id),
            "error_type": type(error).__name__,
            "error_message": str(error)[:1000],
        })

    def dump_jsonl(self, path) -> int:
        """Serialize records to JSONL, return count."""
        with open(path, "w") as f:
            for r in self.records:
                f.write(json.dumps(r) + "\n")
        return len(self.records)

The run_id / parent_run_id pair is how you reconstruct the callback stack in a post-hoc reader — they form a tree.

Verifying propagation

Before you ship a debug bundle, confirm callbacks actually fired inside the subgraph. A useful smoke test:

debug = DebugCallbackHandler()
agent.invoke({"messages": [("user", "what time is it?")]},
             config={"callbacks": [debug], "configurable": {"thread_id": "smoke"}})

# Expect: at least one tool_start record with parent_run_id set (i.e. called
# from inside the agent subgraph, not from the top-level invoke)
assert any(r["kind"] == "tool_start" and r["parent_run_id"] for r in debug.records), \
    "No callbacks fired inside subgraph — P28 regression"

If that assertion fails, the callback was bound at definition time somewhere in the chain construction. Grep for with_config(callbacks= and move all of them to the invoke-time config.

Interaction with other config keys

config["callbacks"] coexists with other propagating keys:

Key Propagates? Common use
callbacks Yes (into subgraphs) Diagnostic handlers
configurable.thread_id Yes LangGraph checkpointer key
configurable.tenant_id Yes Per-request retriever factory
max_concurrency Yes (to .batch() children) P08
recursion_limit Yes P10, P55
tags Yes Free-form metadata for traces
metadata Yes LangSmith trace annotations

A diagnostic invocation should set all of: callbacks, tags (e.g. ["debug-bundle", incident_id]), and metadata (e.g. {"incident_id": "INC-2026-0421-A"}) so the resulting LangSmith trace is immediately findable.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill is a diagnostic utility for LangChain and LangGraph applications designed to bundle environment metadata and event logs. It includes robust sanitization logic to redact API keys and PII. The low risk rating reflects the inherent security surface created by capturing and processing runtime data such as tool inputs and model messages.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 2 months ago
What it can do
Reads files Edits files Runs commands
version
2.7.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
compatibility
Designed for Claude Code
All 5 allowed tools
ReadWriteEditBash(python:*)Bash(pip:*)
Other metadata
tags
[
  "saas",
  "langchain",
  "langgraph",
  "python",
  "langchain-1.0",
  "debugging",
  "observability",
  "incident-response"
]

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/langchain-debug-bundle