unslothai/unsloth · error · RuntimeError
apply_chat_template_for_generation: no attempt produced a re
Error message
apply_chat_template_for_generation: no attempt produced a result
What it means
Raised by apply_chat_template_for_generation when its loop of candidate kwarg attempts (tools on/off, continue_final_message variants, etc.) produced no result AND no exception was recorded — every attempt was skipped via `continue` on TypeError without any call succeeding. It is a defensive invariant: the attempt list was empty or all attempts failed with TypeError.
Source
Thrown at studio/backend/core/inference/chat_template_helpers.py:2555
boundary = _boundary_kwargs if boundary is None else boundary
last_exc: Optional[Exception] = None
for kwargs in attempts:
try:
return tokenizer.apply_chat_template(
_swept_for(kwargs, msgs),
tokenize = False,
**boundary,
**kwargs,
)
except TypeError as e:
last_exc = e
continue
except Exception as e:
last_exc = e
break
if last_exc is not None:
raise last_exc
raise RuntimeError("apply_chat_template_for_generation: no attempt produced a result")
def _render_continuation_manually(msgs: list) -> str:
"""For tokenizers predating ``continue_final_message`` (TypeError above).
Prefix and partial come from the SAME swept copy: an attempt that drops the tools
kwarg re-sweeps for the default template, whose markup would otherwise survive raw.
"""
for kwargs in attempts:
swept = _swept_for(kwargs, msgs)
try:
prefix = tokenizer.apply_chat_template(
swept[:-1], tokenize = False, add_generation_prompt = True, **kwargs
)
except TypeError:
continue
partial = trailing_assistant_text(swept) or _continue_text
return f"{strip_open_reasoning_prefill(prefix)}{partial}"
raise TypeError("no attempt rendered the continuation prefix")View on GitHub (pinned to 203007d190)
Solutions
- Check the transformers version in use; upgrade/downgrade to a version whose apply_chat_template accepts add_generation_prompt and the swept kwargs
- Log each attempt's kwargs and the TypeError to see which signature mismatch repeats, then add a compatible attempt
- As a caller, fall back to rendering the prompt manually (join message contents with the tokenizer's known template) when this RuntimeError fires
Defensive patterns
Strategy: try-catch
Try / catch
try:
prompt = apply_chat_template_for_generation(tokenizer, messages)
except RuntimeError as e:
if "no attempt produced a result" in str(e):
prompt = manual_prompt_render(messages) # known-format fallback Prevention
- Pin a transformers version compatible with the models in use
- Smoke-test apply_chat_template once at startup, not per request
- Log each attempt's kwargs to extend the attempt list for new tokenizer signatures
When it happens
Trigger: A tokenizer whose apply_chat_template signature is incompatible with every attempt (very old transformers); an attempts list built empty because the swept message/kwarg combinations deduplicated to nothing; TypeError raised on the first attempt short-circuiting the loop via `break` with last_exc set is re-raised instead — this specific message means the no-exception no-result branch.
Common situations: transformers version far older/newer than the supported range so all kwarg combinations raise TypeError; a tokenizer class overriding apply_chat_template with an incompatible signature; none of the model card's template variants being applicable.
Related errors
- no attempt rendered the continuation prefix
- Model '{self.active_model_name}' has no chat_template set in
- the template produced an empty prompt
- apply_chat_template returned None — tokenizer may be incompa
- VirusTotal returned HTTP {status} for {_redact_url(url)}
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/ccb77fd9bd5d7e17.
Report an issue: GitHub.