huggingface/smolagents · error · ValueError
Only 'markdown' is supported for a string argument to `code_
Error message
Only 'markdown' is supported for a string argument to `code_block_tags`.
What it means
CodeAgent.__init__ accepts code_block_tags as either a string or a tuple. The only accepted string is the sentinel 'markdown' (which maps to ('```python', '```')); any other string is rejected — custom tags must be passed as an explicit (opening, closing) tuple.
Source
Thrown at src/smolagents/agents.py:1557
use_structured_outputs_internally: bool = False,
code_block_tags: str | tuple[str, str] | None = None,
**kwargs,
):
self.additional_authorized_imports = additional_authorized_imports if additional_authorized_imports else []
self.authorized_imports = sorted(set(BASE_BUILTIN_MODULES) | set(self.additional_authorized_imports))
self.max_print_outputs_length = max_print_outputs_length
self._use_structured_outputs_internally = use_structured_outputs_internally
if self._use_structured_outputs_internally:
prompt_templates = prompt_templates or yaml.safe_load(
importlib.resources.files("smolagents.prompts").joinpath("structured_code_agent.yaml").read_text()
)
else:
prompt_templates = prompt_templates or yaml.safe_load(
importlib.resources.files("smolagents.prompts").joinpath("code_agent.yaml").read_text()
)
if isinstance(code_block_tags, str) and not code_block_tags == "markdown":
raise ValueError("Only 'markdown' is supported for a string argument to `code_block_tags`.")
self.code_block_tags = (
code_block_tags
if isinstance(code_block_tags, tuple)
else ("```python", "```")
if code_block_tags == "markdown"
else ("<code>", "</code>")
)
super().__init__(
tools=tools,
model=model,
prompt_templates=prompt_templates,
planning_interval=planning_interval,
**kwargs,
)
self.stream_outputs = stream_outputs
if self.stream_outputs and not hasattr(self.model, "generate_stream"):
raise ValueError(View on GitHub (pinned to 30bb116109)
Solutions
- Pass a tuple: code_block_tags=('<code>', '</code>') for custom tags.
- Or use the string 'markdown' if you want the default ```python fences.
- Or omit the parameter entirely to accept the default <code> tags.
Example fix
# before
agent = CodeAgent(model=model, tools=[], code_block_tags='xml')
# after
agent = CodeAgent(model=model, tools=[], code_block_tags=('<code>', '</code>')) Defensive patterns
Strategy: validation
Validate before calling
assert isinstance(code_block_tags, tuple) or code_block_tags == 'markdown' agent = CodeAgent(model=model, tools=[], code_block_tags=code_block_tags)
Type guard
def valid_code_block_tags(v) -> bool:
return isinstance(v, tuple) and len(v) == 2 or v == 'markdown' Prevention
- Pass code_block_tags as an explicit (open, close) tuple for custom formats.
- Reserve the string form for the 'markdown' sentinel only.
- Omit the parameter to use defaults when unsure.
When it happens
Trigger: Constructing CodeAgent(model=..., code_block_tags='xml') or any string other than 'markdown'.
Common situations: Users assuming code_block_tags takes a format name like 'xml' or 'html'; migrating configurations where a single string tag was expected.
Related errors
- Unsupported executor type: {self.executor_type}
- No '{split_token}' token provided in your output. Your outpu
- 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/a5dbe14a6ffdf35f.
Report an issue: GitHub.