---
title: "JSON mode and tools do not mix"
lesson_id: "04"
---

# JSON mode and tools do not mix

- **Lesson ID:** 04
- **Goal:** Avoid losing tool calls or fields when JSON output is turned on.
- **Human lesson:** [04-json-mode-and-tools.html](04-json-mode-and-tools.html)

## Prerequisites

- Ollama installed, `ollama pull qwen3:1.7b`.

## Inputs, outputs, and artifacts

- **Inputs:** A tool definition and a prompt.
- **Outputs:** A printed check of `tool_calls` with and without `format: json`.
- **Artifacts:** The test script from the lesson.

## Agent build steps

1. Run the test script from the lesson against Ollama.
2. If tool calls disappear with `format: json`, split the step: tools only, or schema only.
3. Reorder schemas so required fields come first.
4. Log when optional fields are missing after parsing.

## 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

- JSON mode and tool calling both constrain the output.
- Ollama #18944: with `format: json`, tool calls come back as text in `content`.
- llama.cpp #30321: an optional field before a required one can be dropped silently.
- Valid JSON is not the same as complete JSON.

## Takeaways

- Send either tools or a schema in one request, not both.
- Put required fields first and log missing optional fields.
- Keep a CI test that checks `tool_calls` with and without JSON mode.

## Acceptance checks

- Each request sends tools or a schema, not both.
- Links to Ollama #18944 and llama.cpp #30321 are present.
- [ ] Proceed to [lesson 05 brief](05-several-agents-on-one-box.llms.md).
