# Debugging a Tool

Debugging in superglue is agent-first. Tell the playground agent what you expected, what happened instead, and which test input reproduces the problem.

The agent can inspect the current draft and its latest execution results. It tests a focused change and presents the proposed edit for your review.

## Debug a tool with the agent

1. **Set a representative input:** In **Tool Input & State**, enter the JSON values and bind any required files that reproduce the issue.
2. **Run the tool:** Select **Run All Steps** to execute the current draft from start to finish. The playground focuses the first failed step or the final result when execution ends.
3. **Ask the agent to investigate:** Select **Fix in session** on a failed step or transform, or describe an incorrect result in the playground chat. Include the expected result when the run succeeds but the data is wrong.
4. **Review the proposed edit:** The agent tests its change before proposing it. Inspect the diff and accept it only when it matches your intent.
5. **Verify with the same input:** Rerun the affected step or the full tool, then save once the result is correct.

**Caution:** **Run All Steps** asks for confirmation before a step marked as modifying external data. Check the
  target system and test input before continuing.

## Inspect the test input

The **Tool Input & State** card contains tool inputs and saved-tool state:

- **Test Input** or **JSON & File Inputs** contains the current payload and file bindings.
- **State** shows current production state for saved tools. It is read-only and is not used by playground runs.
- **Input Schema** defines the expected input shape. When a schema exists, superglue generates a starting payload and warns before running input that does not match it.
- Required file inputs must be bound before execution. You can still choose **Run Anyway** from the warning when intentionally testing an incomplete case.

Use stable, minimal test data while debugging. If you change the input and the tool at the same time, it is harder to tell which change fixed the problem.

## Isolate a failing step

Each step has three views:

- **Step Input** shows the evaluated `currentItem` together with payload and upstream step data. Run the preceding steps first when this input is not available yet.
- **Step Config** shows the instruction, system connection, request configuration, and optional pagination or advanced settings.
- **Step Result** shows the response data or execution error returned by that step.

Use **Run Step** to test one step without rerunning the full tool. For a loop step, **Run single iteration** tests the first item before you execute the complete loop.

When a step fails, **Fix in session** sends its error to the agent and asks it to diagnose and repair the step.

## Check the final result

The final card turns step results into the tool's returned output:

- **Step Input** shows the data available to the final transform.
- **Transform Code** controls how that data is shaped.
- **Result Schema** optionally validates the returned structure.
- **Result** shows the transformed output or error.

Select **Transform Output** to retest only this layer after the preceding steps have completed. If it fails, use **Fix in session** so the agent can inspect the transform error and propose a correction.

## Verify before saving

1. Rerun the original failing case after you accept an edit.
2. Test one normal case.
3. Test one edge case, such as an empty response or a loop with multiple items.
4. Save only after the final result and any external writes match what you intended.