# Replacing deprecated Workers AI models: same prompts, different parameters

On 2026-11-20 Cloudflare retires a handful of Workers AI models, and four things I run were using them: the "Ask about Patrick" assistant, the comment moderation Function, and two demo workers (a text analysis demo and a capacity advisor). I moved all four to `@cf/google/gemma-4-26b-a4b-it`. This post is what that took.

The short version: my prompts survived the move almost untouched. Everything around the prompts did not.

## Finding the model names was the first problem

I assumed a grep would list every place a model name lives. It did not. In my setup they are spread over four kinds of places:

- a constant in code (the assistant Worker),
- a GitHub repository variable that a workflow turns into an environment variable on a Container App,
- an Azure Function app setting,
- code that I paste into the Cloudflare dashboard by hand, where the copy in the repo can lag behind.

My first inventory was wrong twice. I listed a 1B model for the moderation Function because that is the default in the code, but the live value is an app setting in Azure. It also turned out that the bicep template sets that app setting on every infrastructure run, so changing it in the portal only lasts until the next run. If a model name lives in an app setting, change the template default too.

I wrote the list of places into the repo's CLAUDE.md, so the next deprecation notice starts from a checklist instead of a hunt.

## The prompts stayed

For the assistant I kept the system prompt as it was: grounding rules, an English and Dutch language gate, a marker the model appends when it cannot answer. gemma-4 followed all of it. One result I did not expect: asked to print its own system prompt, Llama 3.1 8B leaked it and gemma-4 refused.

The moderation prompt stayed too. A real Dutch test comment ("Goed geschreven, mooi artikel!") came back scored 5 out of 5 with a correct one line reason, from a model that is a lot bigger than the 1B it replaced.

## What did not carry over

Four things in the requests had to change.

**1. Thinking mode.** gemma-4 is a reasoning model. By default it thinks first, and with a small `max_tokens` the thinking eats the whole budget: `content` comes back empty and `finish_reason` is `length`. The fix that works is `chat_template_kwargs: { enable_thinking: false }`. I also tried `reasoning_effort` and `thinking: { type: "disabled" }`. Neither did anything.

**2. Response shape.** Llama models answer in `response`. gemma-4 answers in an OpenAI style `choices[0].message.content`. Every consumer needed a second code path, including the C# parser in the Function, which got two new tests.

**3. Raw prompts.** The text analysis demo sent a raw `prompt`. gemma-4 answered with rows of `}`. It needs chat `messages`, so the same prompt text now goes in as a user message.

**4. JSON schema mode.** The capacity advisor asks for structured JSON. With `response_format: json_schema`, gemma-4 got stuck in endless blank lines in 3 of 4 runs: 30 seconds, 1,600 tokens, invalid JSON. What works is putting the schema in the prompt and using `json_object` mode: valid JSON in 6 of 6 runs, one to five seconds each. The advisor's worker now normalizes the answer back into the shape the .NET client already expected, so the client did not change.

## A bug that looked like a regression

After the deploy I asked the assistant which certificates Patrick has. It said it had no information about that. It looked like the new model being worse at grounding. It was not.

I replayed the question through the same steps the Worker takes: embed the question, query the knowledge base, look at the top five chunks. The chunk `## Certifications` was in the top five, but it contained only the heading. The list of exam codes sat in the next chunk, and a list of codes like AZ-400 never matches a question about certificates. The page had been split into paragraphs, and a heading is a paragraph of its own.

The fix has two parts. A heading-only block is now joined to the block after it. And a bullet list under a heading gets one descriptive line, "Certifications of Patrick Koorevaar:". Measured with bge-m3, the certification chunk went from rank 14 (similarity 0.454) to rank 1 (0.592). The skills chunk went from 0.36 to 0.53.

Then it was still wrong, for a second reason. The assistant caches the retrieved chunks per question in KV, and that cache is only cleared when the blog API saves an article. I had written the new embeddings straight to Cosmos, so the cache never found out. Re-saving the article with identical content cleared it.

## The model changed the answers

Two side effects showed up once real answers came back. One turned out to be an upgrade.

**It writes Markdown, which is prettier.** Llama gave me plain paragraphs. gemma-4 structures its answers: bold group names, bullet lists, a short intro line. My chat widget showed the answer as plain text, so a certificate list first appeared as `*   **AZ-400**: DevOps Engineer Expert`. I could have told the model to stop, or stripped the Markdown on the server. But the structured version is easier to read in a small chat window, so I made the widget render it instead. A small renderer handles bold, italics, inline code, bullet lists and headings. It builds DOM nodes and never uses `innerHTML`, so nothing a model writes can inject markup. Links and numbered lists stay literal text. The homepage box with recently answered questions uses the same renderer, from one shared file. The same question now gets an answer that looks designed instead of dumped.

**It writes more.** For "What skills does Patrick have?" one run gave 162 words. Output tokens are the expensive side, so I added a rule to the prompt, "at most 3 sentences, or a list of at most 6 short items, direct answer first", and a hard cap of 400 tokens as a safety net. On real retrieved chunks the skills answer dropped to 83 words, and short answers hardly changed (34 to 33 words, 49 to 42). The cap is about 300 words, so it only ever cuts a runaway answer.

One more thing I noticed on a long answer: a "could not reach the assistant" error in the widget, although the answer had been stored. I could not reproduce it with the real page and a mocked response. The long answer is the only suspect I have, so shorter answers are my fix for now, and I will watch for it.

## What it costs

Prices per million tokens, from Cloudflare's pricing page:

| Model | Input | Output |
|---|---|---|
| llama-3.2-1b-instruct | $0.027 | $0.201 |
| llama-3.2-3b-instruct | $0.051 | $0.335 |
| llama-3.1-8b-instruct-fp8 | $0.152 | $0.287 |
| gemma-4-26b-a4b-it | $0.100 | $0.300 |

For the assistant, the move is cheaper on input (about a third less) and about the same on output. The prompt is large, with the rules and five retrieved chunks, so input dominates. For comment moderation the input price is nearly four times higher than the 1B model, but a comment is short and comments are rare, so it rounds to nothing.

## What I would do differently

Four callers, four places, four ways of failing. Each caller carries its own prompt and its own model specific parameters. A deprecation notice should be a change in one place, so I filed a backlog item for a small proxy Worker: callers send data to a named task, and the proxy owns the model, the prompt and the evals. Then the next migration is one deploy, and the parameters that only matter for one model (thinking off, schema in the prompt) stay behind the proxy.

---

*Co-authored with Claude.*

If this was useful, [you can buy me a coffee](https://ko-fi.com/p47k0).

New articles: [follow via RSS](https://blog.koorevaar.com/feed.xml).

Let's connect on [LinkedIn](https://nl.linkedin.com/in/patrickkoorevaar).
