---
title: "Thinking output in the wrong field"
lesson_id: "02"
---

# Thinking output in the wrong field

- **Lesson ID:** 02
- **Goal:** Detect answers and tool calls that land in the wrong field.
- **Human lesson:** [02-thinking-output-in-the-wrong-field.html](02-thinking-output-in-the-wrong-field.html)

## Prerequisites

- Lesson 01 environment.

## Inputs, outputs, and artifacts

- **Inputs:** Chat completion JSON from llama-server, Ollama, or mlx-lm.
- **Outputs:** A parsed reply or a `ParseProblem` with a clear reason.
- **Artifacts:** `safe_parse.py` and a log of each thinking setting.

## Agent build steps

1. Save `safe_parse.py` from the lesson.
2. Run the three bad-case examples and confirm each raises `ParseProblem`.
3. Send the curl request with `enable_thinking` true and false and record where the answer lands.
4. On `ParseProblem`, retry once with a different thinking setting, then fail clearly.
5. Never execute tool markup found in `reasoning_content`.

## Constraints

Keep the language simple, friendly, and literal. No quizzes, no em dashes. Brand Edge FDE only. Use small local models. Do not invent flags, endpoints, or issue numbers. 

## Key concepts

- Replies have `content`, `tool_calls`, and `reasoning_content`.
- A reply can finish with `stop` and still have no usable answer.
- `finish_reason` and the fields can disagree (mlx-lm #1946).
- Thinking can leak into JSON mode even when it is turned off (llama.cpp #30256).

## Takeaways

- Read every reply through one parser that raises on empty or mismatched replies.
- Treat tool markup inside reasoning as a failed turn. Do not run it.
- Test each thinking setting after each runtime update.

## Acceptance checks

- All three bad cases are caught.
- Links to llama.cpp #30246, #30256 and mlx-lm #1946 are present.
- [ ] Proceed to [lesson 03 brief](03-tool-calls-that-do-not-break.llms.md).
