Prompt & Context Engineering·Question 50 of 68Advanced

You moved a prompt from a hosted API to a self-hosted copy of the same open-weight model, and quality dropped below the hosted version. What do you check?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Check the chat template before touching the prompt text. When the same weights do worse self-hosted, the usual cause is that the token sequence the model sees differs from the one it was post-trained on, and the wording is innocent.

Full worked answer with diagram

Check the chat template before touching the prompt text. When the same weights do worse self-hosted, the usual cause is that the token sequence the model sees differs from the one it was post-trained on, and the wording is innocent.

The model learned roles, tool calls and turn boundaries as specific special-token sequences. Your serving stack renders messages into that sequence through the chat template shipped with the tokenizer. Small deviations push the model off-distribution:

  • Wrong or missing template. A generic template or hand-built strings instead of the model's own. Symptoms: rambling, role confusion, the model writing the user's next turn.
  • No generation prompt. Without the assistant header at the end (add_generation_prompt=True in Hugging Face's apply_chat_template), the model may continue the user's message instead of answering it.
  • Doubled special tokens. The template already inserts BOS, then tokenizing the rendered string adds another. The quality loss is subtle and easy to miss.
  • Unsupported roles. Some model families have no system role, and their templates fold the system prompt into the first user turn or drop it.
  • Wrong stop tokens. An end-of-turn token not registered as a stop sequence gives run-on output.
  • Tool-call format. The server's tool-call parser must match the model's trained format, or valid calls come back as plain text.
  • Reasoning toggles and sampling defaults. Some templates switch thinking on or off with a flag. Model cards often recommend sampling settings that hosted providers apply and your stack may not.

The method: log the exact token ids for one request, decode them, and diff against the reference rendering from the model's own tokenizer. Then run the same eval through both endpoints at identical sampling settings. Only once the token sequences match is it worth blaming quantization or the prompt.

Worth sketching. Laying out the rendering path shows every place where the token sequence can drift from what the model was trained on.

flowchart LR
    A["Messages and tools"] --> B["Model's own<br/>chat template"]
    B --> C["Rendered string with<br/>role and turn tokens"]
    C --> D["Tokenize without<br/>a second BOS"]
    D --> E["Generate with recommended<br/>sampling and stop tokens"]
    E --> F["Tool-call parser matching<br/>the trained format"]
    G["Diff token ids against<br/>the reference rendering"] --> D

What a good answer covers

  • Check the chat template before touching the prompt text
  • When the same weights do worse self-hosted, the usual cause is that the token sequence the model sees…
  • The model learned roles, tool calls and turn boundaries as specific special-token sequences
  • Your serving stack renders messages into that sequence through the chat template shipped with the tokenizer
  • Wrong or missing template

Key terms: Wrong or missing template · No generation prompt · Doubled special tokens · Unsupported roles · Wrong stop tokens · Tool-call format · Reasoning toggles and sampling defaults

Interviewer follow-ups to expect

  1. How would you build a regression test that fails when someone changes the chat template?

  2. Why can a template that drops the system prompt still pass a casual smoke test?

  3. Once the token sequences match and quality is still lower, what do you suspect next?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep