Model habit or encoding bug: fixing broken diacritics

APIDeepSeekFreeKey · Updated 2026-11-22 · 8 min read

Letterpress type blocks with separate accent pieces
An accented letter can lose its mark anywhere along the way.

A frustrating report from people running assistants in French, Spanish, Portuguese, German or Vietnamese: the replies arrive without accents. 'Deja' instead of 'déjà', 'cafe' instead of 'café'. Some try to fix it by adding skills or instructions to their agent and see little change. Others see a different symptom: accented letters turn into odd pairs like 'é', black diamonds with question marks, or characters that vanish at random points in a streamed reply.

These look similar but have very different causes. Some are the model's writing habits, which you fix with prompts and examples. Others are bugs in your own pipeline, such as how a streaming response is decoded, how a bot sends text, or how a page declares its charset, which no prompt can fix. This article shows how to tell them apart in a few minutes and how to fix each one.

Examples use the keyless free-ai endpoint on this site, an independent open-weight model of about 35B parameters; the site is not affiliated with DeepSeek. The pipeline fixes apply equally to DeepSeek's API and any other provider.

Frequently asked questions

Why would a model leave out accents on purpose?

It is not deliberate, but it is learned. Informal web text, chat logs and some training data contain lots of unaccented writing, especially in messaging contexts. If the conversation looks informal, or the system prompt is in English, the model may imitate that style.

What does mojibake like 'é' mean?

It means UTF-8 bytes were decoded as if they were a single-byte encoding such as Latin-1 or Windows-1252. The model produced correct text; something in your pipeline read it with the wrong charset.

Why do characters disappear only in streamed replies?

Accented letters take two or more bytes in UTF-8. A network chunk can end in the middle of a character. If each chunk is decoded separately, the split character becomes garbage or is dropped. Decoding with a streaming decoder fixes it.

How does Unicode normalisation affect accented text?

An accented letter can be stored as one precomposed character or as a base letter plus a combining accent. Both look the same but compare differently in code and may display oddly in some fonts. Normalising to NFC makes them consistent.

Which is better for fixing missing accents: a prompt or post-processing?

A prompt, every time. Restoring accents afterwards with code is error-prone because many words are ambiguous without context. Fix the model's style at the source and fix encoding bugs in the pipeline.

Does the language of the system prompt matter?

Often, yes. A system prompt written in the target language, with correctly accented text, is a strong signal of the expected style. An English system prompt with a single line saying 'answer in French' is weaker.

Can a messaging bot platform strip accents?

Platforms themselves generally handle Unicode well. Problems usually come from the bot code: wrong encoding when building requests, escaping for a markup mode, or a library configured with an old default.

A two-minute diagnosis

Before changing anything, find out where the text goes wrong. Make one non-streaming request directly to the API from a terminal and look at the raw JSON. If the accents are present there, the model is fine and the problem is in your code. If they are missing there too, it is the model's style, and you need to change the prompt.

The command below asks for a short French sentence and prints the raw response. Modern terminals display UTF-8 correctly; JSON may also show characters as \u00e9 escapes, which are perfectly valid and mean the accent is there.

Accents present in raw output

Your pipeline is losing them. Check decoding of streams, charset headers, bot libraries and any text cleaning functions.

Accents missing in raw output

The model is writing without them. Move on to the prompting fixes below; no amount of encoding work will help.

curl -s https://api.apideepseekfreekey.com/v1/chat/completions \
  -H 'Content-Type: application/json; charset=utf-8' \
  -d '{"model":"free-ai","max_tokens":80,"messages":[{"role":"user","content":"Écris une phrase sur un café à côté de la gare."}]}' \
  | python3 -c 'import sys, json; print(json.load(sys.stdin)["choices"][0]["message"]["content"])'

When the model is the cause

Models mirror the register of the conversation. If the user writes quickly on a phone without accents, the model may answer the same way. If the system prompt is in English and the agent framework adds English tool descriptions, the model may treat the target language as secondary and write a looser version of it. Smaller and faster models are more prone to this than large ones.

The fixes are about signals. Write the system prompt in the target language with correct accents, state the expectation explicitly, and include a short example reply. If the agent framework injects its own instructions, check whether they are in English and whether you can localise them.

Examples outweigh rules

One correctly accented example sentence in the system prompt often does more than a paragraph of instructions about spelling.

Watch agent-added text

Agent frameworks may append long English instructions after yours. If accents return when you test without the framework, its added text is diluting your signal.

from openai import OpenAI

client = OpenAI(base_url="https://api.apideepseekfreekey.com/v1", api_key="free")

SYSTEM_FR = (
    "Tu es un assistant francophone. Écris toujours en français correct, "
    "avec tous les accents (é, è, à, ç, ê, ô) et la ponctuation française. "
    "Exemple de style : « Bien sûr, voici la réponse à ta question. »"
)

r = client.chat.completions.create(
    model="free-ai",
    max_tokens=200,
    messages=[
        {"role": "system", "content": SYSTEM_FR},
        {"role": "user", "content": "c est quoi la difference entre un cafe creme et un cafe au lait"},
    ],
)
print(r.choices[0].message.content)
Cafe terrace table with coffee and a notebook
Prompts written in the target language set the expected style.

Split characters in streaming responses

The most common pipeline bug appears only with "stream": true. Server-sent events arrive as byte chunks, and the boundaries fall wherever the network puts them. An 'é' is two bytes in UTF-8; an emoji is four. If a chunk ends after the first byte and your code decodes each chunk independently, the half character becomes a replacement symbol or disappears.

In browsers, the fix is a single option: pass { stream: true } to TextDecoder.decode, which keeps incomplete bytes for the next call. In Python, read lines from a properly configured client or use an incremental decoder.

Python equivalent

With httpx or requests, iterate over lines with the encoding set to UTF-8, or feed raw bytes through codecs.getincrementaldecoder('utf-8')() so split characters are reassembled.

Why it looks random

Chunk boundaries vary with network timing, so the same reply may be fine once and broken the next time. Intermittent missing letters are a strong hint of this bug.

// Wrong: each chunk decoded on its own can split multi-byte characters
// text += new TextDecoder().decode(value);

// Right: one decoder, stream mode keeps partial bytes between chunks
const decoder = new TextDecoder("utf-8");
let buffer = "";
function onChunk(value) {
  buffer += decoder.decode(value, { stream: true });
  const lines = buffer.split("\n");
  buffer = lines.pop();
  return lines;
}
function onEnd() {
  buffer += decoder.decode(); // flush anything left
  return buffer;
}

Mojibake from the wrong charset

If accented letters become pairs like 'é' or 'è', UTF-8 text was read as Windows-1252 or Latin-1. Typical culprits: a web page without a charset declaration, a server that sends text/html without charset=utf-8, a database connection configured with an old default, or a log file opened with the wrong encoding in an editor.

Fix it at every boundary. Declare <meta charset="utf-8"> in HTML, send charset in content-type headers, set database connections and tables to UTF-8 (in MySQL, utf8mb4), and open files with an explicit encoding in code.

Double encoding

Sometimes text is encoded to UTF-8 twice, producing even stranger sequences. That usually means a string was already text but got treated as bytes and encoded again. Trace it to the line that calls encode or decode needlessly.

  • HTML: <meta charset="utf-8"> as the first element in head
  • HTTP: Content-Type: application/json; charset=utf-8
  • Python: open(path, encoding="utf-8"), never the platform default
  • Databases: UTF-8 everywhere, including the connection
  • Terminals and editors: confirm they display UTF-8
Chocolate bar broken with one square split
Network chunks can split a multi-byte character in two.

Chat bots and markup escaping

Messaging bots add their own layer. Many bot APIs offer a markup mode, such as Markdown or HTML, which requires certain characters to be escaped. Escaping functions written for English text sometimes strip or mangle characters outside ASCII, and some older libraries normalise text in ways that drop combining accents.

Test by sending the model's raw reply as plain text with no markup mode. If accents survive, the problem is your escaping or formatting step. Use the escaping helper your bot library provides, and avoid regular expressions that whitelist only a-z.

Voice pipelines deserve a check too. If messages are transcribed before reaching the model, a transcription model configured for the wrong language will produce unaccented or misspelled text, and the language model will faithfully answer in the same style. Set the transcription language explicitly when you know it.

Beware ASCII-only cleaning

A pattern like [^a-zA-Z0-9 ] used to 'clean' text deletes every accented letter. Use Unicode-aware classes, such as \w with Unicode enabled, or do not clean at all.

Length limits

Bots that truncate messages by byte length can cut a character in half. Truncate by characters, or better, by whole words.

Normalisation and comparisons

Even when text displays correctly, code can trip over it. The same visible 'é' might be one code point or two. Searching, deduplication, caching and comparisons can then fail silently: a cached answer for 'café' is not found for 'café', which looks identical but stores the accent as a separate combining mark. Normalising every string to NFC when it enters your system avoids these surprises.

In JavaScript use str.normalize("NFC"); in Python unicodedata.normalize("NFC", s). Apply it to user input, model output and stored data consistently.

Normalising early also keeps token counts and cache keys stable, which matters if you deduplicate requests before sending them to a model.

Search and retrieval

If you build keyword search over multilingual text, as in the browser retrieval demo, normalise both documents and queries the same way, and consider folding accents only for matching, never for display.

Two nearly identical keys on a table
The same visible letter can have two different encodings.

Languages beyond accents

Everything above applies with more force to scripts that rely heavily on combining marks or multi-byte characters: Vietnamese with its stacked diacritics, Hindi and other Indic scripts, Arabic with optional vowel marks, Thai, and emoji in any language. Streaming decoding bugs show up faster, and font support on users' devices matters too.

Model quality also varies more by language than by any other single factor. A mid-sized open model writes well in widely represented languages and less fluently in others. Large commercial models are generally stronger in lower-resource languages, which is worth testing if your audience writes in one.

Test with real user text

Collect a few dozen genuine messages in each language you support and run them end to end through your app, not just through the API, to catch pipeline issues early.

A checklist for multilingual pipelines

Most accent problems disappear with a short list of habits. Write prompts in the target language with correct accents. Decode streams with a streaming decoder. Declare UTF-8 at every boundary. Avoid ASCII-only cleaning and byte-based truncation. Normalise to NFC. Test end to end with real text.

If accents are still missing after all that, the remaining cause is the model's style in that language. Then compare with another model on the same prompts; routing one language to a stronger model can be a sensible fix, as described in routing between models. For a full bot example, see building a small chat bot assistant.

Keep a multilingual regression set

Add a few accented prompts to your regular tests and check that replies contain expected characters. A simple search for 'é' or 'ç' in the output catches regressions automatically.

Globe beside a stack of dictionaries
Test every language your users write in, end to end.
Try the free API

Open the home page and send a request to the keyless endpoint straight from your browser, no account or key needed.

Read also