huggingface/smolagents · error · AgentParsingError
No '{split_token}' token provided in your output. Your outpu
Error message
No '{split_token}' token provided in your output.
Your output:
{model_output}
. Be sure to include an action, prefaced with '{split_token}'! What it means
CodeAgent parses model output expecting an 'Code:'/'Action:' split token before the action block. extract_action splits the model output on that token; if the token is absent (or the trailing part is empty), it raises AgentParsingError telling you to preface the action with the token.
Source
Thrown at src/smolagents/agents.py:804
"""
return list(self._step_stream(memory_step))[-1]
def extract_action(self, model_output: str, split_token: str) -> tuple[str, str]:
"""
Parse action from the LLM output
Args:
model_output (`str`): Output of the LLM
split_token (`str`): Separator for the action. Should match the example in the system prompt.
"""
try:
split = model_output.split(split_token)
rationale, action = (
split[-2],
split[-1],
) # NOTE: using indexes starting from the end solves for when you have more than one split_token in the output
except Exception:
raise AgentParsingError(
f"No '{split_token}' token provided in your output.\nYour output:\n{model_output}\n. Be sure to include an action, prefaced with '{split_token}'!",
self.logger,
)
return rationale.strip(), action.strip()
def provide_final_answer(self, task: str) -> ChatMessage:
"""
Provide the final answer to the task, based on the logs of the agent's interactions.
Args:
task (`str`): Task to perform.
images (`list[PIL.Image.Image]`, *optional*): Image(s) objects.
Returns:
`str`: Final answer to the task.
"""
messages = [
ChatMessage(View on GitHub (pinned to 30bb116109)
Solutions
- Retry the run; format deviations are often non-deterministic and succeed on a second attempt
- Use a stronger instruction-following model or increase max_tokens to avoid truncation before the Code: block
- Tighten the system/prompt template to repeat the required output format, or switch to ToolCallingAgent if the model is tuned for native tool calling
- Catch AgentParsingError and feed the error message back to the model as a corrective next step (the error text already instructs it)
Example fix
# before (model output):
I should search for the weather then report back.
# -> AgentParsingError: No 'Code:' token provided
# after (model output):
I should search for the weather.
Code:
py
weather = get_weather("Paris")
final_answer(f"It's {weather}")
Defensive patterns
Strategy: retry
Try / catch
from smolagents import AgentParsingError
try:
agent.run(task)
except AgentParsingError as e:
# feed the parser complaint back for one corrective retry
result = agent.run(str(e) + "\nFollow the required format exactly.") Prevention
- Use instruction-tuned models with adequate max_tokens for CodeAgent
- Keep the system prompt's format instructions prominent and unmodified
- Consider ToolCallingAgent for models that natively emit tool calls
When it happens
Trigger: A CodeAgent step where the LLM outputs only prose/thoughts without a final 'Code:' block; the model uses a variant like '```python' or 'Action:' instead of the expected token; empty or truncated output after the token causes the split/unpack to fail.
Common situations: Using a weaker or non-instruct model that ignores the ReAct format; overly chatty system prompts that bury the format instructions; token/stream truncation by max_tokens; tool-calling-formatted output in a CodeAgent.
Related errors
- Only 'markdown' is supported for a string argument to `code_
- Unsupported executor type: {self.executor_type}
- Managed agents are not yet supported with remote code execut
- Error in generating model output: {e}
- Error in code parsing: {e} Make sure to provide correct code
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/bc196ef34f76addd.
Report an issue: GitHub.