Bad Request: can't parse entities — Telegram bot error and how to fix it
Bad Request: can't parse entities means Telegram could not read the formatting in your message: with parse_mode set to HTML, Markdown or MarkdownV2, some text — usually a user's name, a username with an underscore, a price with a dot, or an unclosed tag — breaks the markup. Escape that text for the parse mode you use, send entities instead of parse_mode, or send it without parse_mode.
By Livops team, the people who build and run LivopsUpdated
The error, as the Telegram Bot API returns it with error code 400, comes in a few shapes[2][3][4]:
Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 14
Bad Request: can't parse entities: Unsupported start tag "3" at byte offset 2
Bad Request: can't parse entities: Character '.' is reserved and must be escaped with the preceding '\'
In short: the message was sent with parse_mode (HTML, Markdown or MarkdownV2), and its text contains markup Telegram cannot read, so nothing was sent. The text that breaks it is usually inserted from outside: a name or username with _ or *, a < in HTML, a . or - that MarkdownV2 wants escaped, or a tag left open. Escape every value you insert for the parse mode you use — in HTML only <, > and & — or send entities instead of parse_mode, or send the text without parse_mode.
Each library wraps it in its own words:
| Library | What you see |
|---|---|
| aiogram 3 | TelegramBadRequest: Telegram server says - Bad Request: can't parse entities: ...[5] |
| python-telegram-bot | telegram.error.BadRequest: Can't parse entities: can't find end of the entity starting at byte offset 14[6] |
| grammY | GrammyError: Call to 'sendMessage' failed! (400: Bad Request: can't parse entities: ...)[7] |
| Telegraf | TelegramError: 400: Bad Request: can't parse entities: ...[8] |
python-telegram-bot drops the Bad Request: prefix and capitalizes the rest, which also lowercases everything after the first letter[6]. This page explains what each variant means, how to find the byte it points at, the usual causes, and three fixes — escaping, entities, or no parse mode — in aiogram, python-telegram-bot, grammY and Telegraf.
What does the error mean?
A message’s text can carry formatting in two ways: as markup in the text, read according to parse_mode (HTML, MarkdownV2 or the legacy Markdown), or as a list of entities sent next to plain text, which can be specified instead of parse_mode[1]. With parse_mode set, the Bot API server parses the text first; when parsing fails, the request fails with this error and nothing is sent[4][3].
The part after can't parse entities: tells you which parser failed and why[2]:
| Message | Parse mode | What broke |
|---|---|---|
Can't find end of the entity starting at byte offset N |
Markdown | A _, *, ` or [ opened an entity that never closes |
Can't find end of ... entity at byte offset N |
MarkdownV2 | The same, for MarkdownV2 |
Character 'X' is reserved and must be escaped with the preceding '\' |
MarkdownV2 | A reserved character in plain text, not escaped |
Unsupported start tag "x" at byte offset N |
HTML | A < followed by something that is not a supported tag |
Unclosed start tag at byte offset N |
HTML | A < with no > after it |
Can't find end tag corresponding to start tag "b" |
HTML | An opened tag that is never closed |
Byte offset, not character
N is a position in the text you sent, counted in bytes of its UTF-8 encoding from zero[2]. A Latin letter is one byte, a Cyrillic letter two, most emoji four. In New user: john_doe the underscore is at byte 14 and character 14; in Привет, john_doe it is at byte 18 but character 12. To see what is at the offset, slice the bytes:
offset = 18 # from the error
print(text.encode("utf-8")[offset:offset + 30].decode("utf-8", "replace"))
const offset = 18; // from the error
console.log(Buffer.from(text, "utf8").subarray(offset, offset + 30).toString());
Entities use a third unit: their offset and length are counted in UTF-16 code units[1]. That only matters if you build the entities list by hand; the library helpers below do it for you.
Causes, most common first
1. User text inside a formatted message
await message.answer(f"Welcome, <b>{user.full_name}</b>!", parse_mode="HTML")
Fine until a user’s name contains <, or with Markdown, until a username has an _. In HTML, every <, > and & that is not part of a tag or an entity must be replaced with <, > and &[1]. A name like I <3 you fails with Unsupported start tag "3"[2]. Anything that comes from outside — names, usernames, captions, search results, error messages, API responses — has to be escaped before it goes into markup.
2. A parse mode set for every message
aiogram’s DefaultBotProperties(parse_mode=...) sets the default parse mode for all messages[14], and the other libraries have similar defaults. Then a plain message.answer(text) that echoes user text is parsed as markup too, without anything in that line saying so.
3. Legacy Markdown and MarkdownV2 are different
- Markdown (legacy, kept for backward compatibility) has
*bold*,_italic_, links and code only. Outside an entity you escape just_,*,`and[with\, entities cannot be nested, and escaping inside an entity is not allowed[1]. - MarkdownV2 adds underline, strikethrough, spoilers and quotes, and outside entities requires
\before each of_ * [ ] ( ) ~ ` > # + - = | { } . ![1]. That is whyPrice: 10.5orDone!fails withCharacter '.' is reserved.
Escaping for one and sending as the other fails: text escaped for legacy Markdown still has bare dots and dashes that MarkdownV2 rejects.
4. HTML that Telegram does not support
Only the tags in the API’s list work: b, strong, i, em, u, ins, s, strike, del, span class="tg-spoiler", tg-spoiler, a, code, pre, blockquote and a few Telegram-specific ones[1]. <br>, <p>, <div> or <ul> give Unsupported start tag. Use a newline instead of <br>. Of named HTML entities, only <, >, & and " are supported; numerical entities all work[1].
5. A message cut in the middle
A message’s text may be at most 4096 characters after entities parsing[1]. Cutting a long formatted string at a fixed length can cut a closing tag or * off, and the remaining half no longer parses. Split on line boundaries, or split the plain text and format each part.
How to fix it
Option 1: escape the text for the parse mode (prefer HTML)
HTML needs only three characters escaped[1], and every language already has a function for it. That makes it the safer mode for user text.
Python, any library: html.escape converts &, < and >, and by default " and ' too[9]:
import html
name = html.escape(user.full_name)
await bot.send_message(chat_id, f"Welcome, <b>{name}</b>!", parse_mode="HTML")
aiogram 3: html.quote() does the same, as the formatting docs show with html.quote(message.from_user.full_name)[10]; it calls html.escape without quoting " and '[11]. For MarkdownV2, md.quote() puts \ before every MarkdownV2 reserved character and before \ itself[11]. Both come from from aiogram import html, md[12].
python-telegram-bot: telegram.helpers.escape_markdown(text, version=2) for MarkdownV2. The default is version=1, legacy Markdown[15], so pass version=2 explicitly:
from telegram.helpers import escape_markdown
text = f"*Order* for {escape_markdown(user.full_name, version=2)}"
await bot.send_message(chat_id, text, parse_mode="MarkdownV2")
grammY and Telegraf (Node): neither ships an HTML escape function that we could find in its documentation; a short one is enough:
const escapeHtml = (s) =>
s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
await ctx.reply(`Welcome, <b>${escapeHtml(ctx.from.first_name)}</b>!`, {
parse_mode: "HTML",
});
Escape only the inserted values, never the whole message: escaping your own <b> tags turns them into visible text.
Option 2: send entities instead of parse_mode
Send the text exactly as it is, with an entities list that marks which ranges are bold, links and so on[1]. Nothing in the text is parsed, so nothing needs escaping. Do not send both: when parse_mode is set, the Bot API server parses the text and does not use the entities you passed[4].
aiogram 3 builds the list from Text, Bold and the other elements, without tag parity or escaping user input[10]. as_kwargs() returns text and entities and sets parse_mode to None, so a default parse mode does not apply[10][13]:
from aiogram.utils.formatting import Bold, Text
content = Text("Welcome, ", Bold(message.from_user.full_name), "!")
await message.answer(**content.as_kwargs())
grammY: the parse-mode plugin’s fmt template tag tracks offsets and lengths for you, and values you put inside it are plain text[16]:
import { b, fmt } from "@grammyjs/parse-mode";
const msg = fmt`Welcome, ${b}${ctx.from.first_name}${b}!`;
await ctx.reply(msg.text, { entities: msg.entities });
Telegraf: fmt and bold from telegraf/format[17]. sendMessage accepts the result directly[19], and a formatted string with entities leaves parse_mode unset[18]:
const { fmt, bold } = require("telegraf/format");
await ctx.reply(fmt`Welcome, ${bold(ctx.from.first_name)}!`);
Option 3: drop parse_mode
parse_mode is optional[1]. A message that needs no formatting — an echo, a log line, an error report — can go out as plain text, and then no character in it means anything. If you set a default parse mode, send these messages with entities (Option 2) or turn the default off for them.
How to confirm the fix
Send yourself a message built from the hardest text you can think of, through the same code path users hit:
john_doe *star* [link] (x) 10.5 - done! a < b & c > d <3 "quotes" Привет 👋
It should arrive exactly as typed, with your own formatting around it.
On Livops
This error happens while the bot runs, the first time a message with the bad text is sent; a deploy does not send your messages, so it can be green while one command fails.
- Logs. The error line, with its byte offset, is on the project’s Logs page;
livops logs <service> -ffollows it from the terminal. Log the failing text next to the error so you can slice the bytes, and remember it may be a user’s data. - If it crashes the bot. If the error stops the process, the bot is started again, and the project page counts the restarts. If it keeps falling over, it is stopped, and you are told with the last line it printed — in the cabinet, and in Telegram if your account is linked.
- Ship the fix with a push. On every push the old bot is stopped before the new one starts, so two copies never answer at once.
A bot costs 19 credits a month (19,000 so’m); see Pricing.
Questions
What does can't parse entities mean in Telegram?
The message was sent with parse_mode set to HTML, Markdown or MarkdownV2, and Telegram could not read the markup in its text. Nothing was sent. The rest of the message says what broke: an entity that never ends, a tag Telegram does not support, or a character MarkdownV2 wants escaped.
What is the byte offset in the error?
The position where the broken markup starts, counted in bytes of the UTF-8 text from zero, not in characters. Latin letters are one byte, Cyrillic letters two, most emoji four, so in non-English text the byte offset is larger than the character position. Encode the text as UTF-8 and look at that byte.
Should I use HTML or MarkdownV2 for a Telegram bot?
HTML when the message contains text you did not write. In HTML only three characters need escaping, less than, greater than and ampersand, and they are easy to escape in any language. MarkdownV2 reserves eighteen characters outside entities, including the dot, the dash and brackets, so ordinary text breaks it often.
Why does my username with an underscore break the message?
In Markdown and MarkdownV2 an underscore starts italic text. A name like john_doe opens an italic entity that never closes, so Telegram cannot find its end. Escape the underscore, or send the message as HTML or with entities.
How do I escape text for MarkdownV2 in python-telegram-bot?
Use telegram.helpers.escape_markdown(text, version=2). The version matters: it defaults to 1, which escapes only the legacy Markdown characters and leaves dots, dashes and brackets that MarkdownV2 rejects.
Can I send formatting without parse_mode?
Yes. Send the text as it is with an entities list that says which ranges are bold, italic or links. Nothing in the text is parsed, so nothing needs escaping. aiogram's formatting utilities, grammY's parse-mode plugin and Telegraf's format module build the list for you.
Why does it work in English but fail for some users?
Because the text that breaks it comes from them: a name with an underscore, an asterisk or a less-than sign, a message with a dot in MarkdownV2. Test the bot with such text before you ship, and escape every value you insert into a formatted message.
Sources
- Telegram Bot API — Formatting options, sendMessage, MessageEntity (core.telegram.org). Checked .
- TDLib source — td/telegram/MessageEntity.cpp (raw.githubusercontent.com). Checked .
- TDLib source — td/telegram/SynchronousRequests.cpp (raw.githubusercontent.com). Checked .
- Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/exceptions.py (raw.githubusercontent.com). Checked .
- python-telegram-bot source — telegram/error.py (raw.githubusercontent.com). Checked .
- grammY source — src/core/error.ts (raw.githubusercontent.com). Checked .
- Telegraf source — src/core/network/error.ts (raw.githubusercontent.com). Checked .
- Python — html, HyperText Markup Language support (docs.python.org). Checked .
- aiogram — Formatting (docs.aiogram.dev). Checked .
- aiogram source — aiogram/utils/text_decorations.py (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/__init__.py (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/utils/formatting.py (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/client/default.py (raw.githubusercontent.com). Checked .
- python-telegram-bot — telegram.helpers (docs.python-telegram-bot.org). Checked .
- grammY — Parse Mode plugin (parse-mode) (grammy.dev). Checked .
- Telegraf source — src/format.ts (raw.githubusercontent.com). Checked .
- Telegraf source — src/core/helpers/formatting.ts (raw.githubusercontent.com). Checked .
- Telegraf source — src/telegram.ts (raw.githubusercontent.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your botRelated
- Bad Request: message text is empty — Telegram bot error and how to fix itBad Request: message text is empty means your bot called sendMessage or editMessageText with no text: an empty string, a variable that came back empty, or no text parameter at all. Text made only of spaces and line breaks fails too, as text must be non-empty. Check the text before you send, and send a fallback line instead.
- Bad Request: message is too long — Telegram bot error and how to fix itBad Request: message is too long means your bot tried to send more than 4096 characters in one text message, counted after HTML or Markdown is parsed out. A caption has a lower limit, 1024 characters, and fails as message caption is too long. Split the text at paragraph or line breaks before you format it and send each part as its own message, or send the whole text as a .txt document.
- Telegram 401 Unauthorized, InvalidToken, TokenValidationError — how to fix the bot token401 Unauthorized means Telegram does not accept your bot's token: it is mistyped, has a space, quote or newline around it, was replaced in @BotFather, belongs to a deleted bot, or never reached the server because the variable is not set. Call getMe with curl to see what Telegram says, put the current token from @BotFather in the variable, and start the bot again.
- Telegram 400: Bad Request: chat not found — how to fix itThe bot asked Telegram for a chat it does not know. Either the chat_id is wrong (a typo, a channel id without its -100 prefix, a user's @username, an id cut to 32 bits), or it is right but this bot has never been in that chat: the user never pressed Start, the bot was never added to the group or channel, or the token belongs to a different bot.
- Telegram 429: Too Many Requests, flood control: retry after N — how to fix itTelegram flood control (429 Too Many Requests) is telling your bot to slow down: wait the number of seconds in retry_after, then send the same request again. It comes from sending too fast — more than about one message a second to one chat, 20 a minute to a group, or about 30 a second in a broadcast. Wait and retry in code, and send broadcasts from one queue at a steady pace.
- Telegram 403: Forbidden: bot was blocked by the user — how to handle itThe user blocked the bot, and Telegram refuses every message the bot sends them. Nothing is broken and a retry will not help: catch the 403, mark that user as inactive in your database, skip them in broadcasts, and mark them active again when they write to the bot.
- Telegram bot hosting in 2026: the options comparedA Telegram bot needs a process that never stops, or a public HTTPS address for a webhook. On Livops it runs from a GitHub push for 19 credits a month (19,000 so'm). Here is how a VPS, Railway, Render, Fly.io and Vercel compare.
- aiogram bot hosting: how to deploy an aiogram 3 botAn aiogram 3 bot needs one process that never stops, the token in an environment variable, state kept outside memory and a clean exit on SIGTERM. On Livops you push a repository with bot.py and requirements.txt, and it runs for 19 credits a month (19,000 so'm), polling or webhook.
- python-telegram-bot hosting: deploying a v22 botA python-telegram-bot bot runs as one Application: run_polling() for polling, run_webhook() with the webhooks extra for a webhook. Both stop cleanly on SIGTERM. On Livops it runs from a push with bot.py and requirements.txt for 19 credits a month (19,000 so'm).
- grammY bot deploy: polling, webhooks and hostingDeploy a grammY bot as one always-on Node.js process: bot.start() for polling, or webhookCallback() behind an HTTP server, with bot.stop() on SIGTERM. On Livops a repository with grammy in package.json runs as a bot from every push, for 19 credits a month (19,000 so'm).
- Telegraf bot hosting: deploying a Telegraf 4 bot on Node.jsA Telegraf bot is one Node.js process: bot.launch() for polling, or bot.webhookCallback() behind an HTTP server for a webhook, with bot.stop() on SIGTERM. On Livops a repository with telegraf in package.json is run as a bot from every push, for 19 credits a month (19,000 so'm).
- Bad Request: CHAT_SEND_WEBPAGE_FORBIDDEN — Telegram bot error and how to fix itBad Request: CHAT_SEND_WEBPAGE_FORBIDDEN means Telegram refused a message because it would put a link preview into a chat where your bot is not allowed to add web page previews. Turn the preview off with link_preview_options and is_disabled, send the text yourself instead of forwarding it, or make the bot an administrator of the group.