agentscope-ai/agentscope · error · ValueError
Each schema must be a dict with 'type' as 'function' and 'fu
Error message
Each schema must be a dict with 'type' as 'function' and 'function' key, got {value} What it means
The DashScope model adapter requires each tool schema to be an OpenAI-style dict with type=='function' and a 'function' key. Passing raw function dicts (missing the wrapper), malformed schemas, or non-dict entries raises ValueError in _format_tools.
Source
Thrown at src/agentscope/model/_dashscope/_model.py:516
`tuple[list[dict] | None, str | dict | None]`:
A tuple of (formatted_tools, formatted_tool_choice).
"""
if tool_choice and tools:
self._validate_tool_choice(tool_choice, tools)
if tool_choice.tools:
allowed = set(tool_choice.tools)
tools = [t for t in tools if t["function"]["name"] in allowed]
fmt_tools = None
if tools:
for value in tools:
if (
not isinstance(value, dict)
or "type" not in value
or value["type"] != "function"
or "function" not in value
):
raise ValueError(
f"Each schema must be a dict with 'type' as "
f"'function' and 'function' key, got {value}",
)
fmt_tools = tools
if not tool_choice:
return fmt_tools, None
mode = tool_choice.mode
if mode not in _TOOL_CHOICE_LITERAL_MODES:
return fmt_tools, {
"type": "function",
"function": {"name": mode},
}
if mode == "required":
warnings.warn(View on GitHub (pinned to e90f1c7592)
Solutions
- Wrap each tool in the OpenAI function envelope: {'type': 'function', 'function': {'name': ..., 'description': ..., 'parameters': ...}}
- Prefer registering tools via agentscope Toolkit so schemas are generated in the correct format
- Validate each entry with the check shown in the error before submitting
Example fix
# before
tools = [{'name': 'get_weather', 'parameters': {...}}]
# after
tools = [{'type': 'function',
'function': {'name': 'get_weather', 'description': '...', 'parameters': {...}}}] Defensive patterns
Strategy: validation
Validate before calling
def check_tools(tools):
for t in tools:
assert isinstance(t, dict) and t.get('type') == 'function' and 'function' in t, f'bad tool schema: {t}' Type guard
def is_openai_tool_schema(t) -> bool:
return isinstance(t, dict) and t.get('type') == 'function' and isinstance(t.get('function'), dict) and 'name' in t['function'] Prevention
- Generate schemas via agentscope Toolkit instead of hand-writing
- Validate tool payloads in tests before sending to the provider
When it happens
Trigger: Passing tools=[{'name': 'foo', 'parameters': {...}}] (no type/function wrapper), or mixing in JSON-schema objects directly instead of the {'type':'function','function':{...}} envelope.
Common situations: Hand-building tool schemas; converting from other frameworks (Anthropic-style input_schema) without wrapping; passing toolkit.get_schemas() output of the wrong shape.
Related errors
- Invalid tool name '{mode}' in tool_choice.mode. Available to
- Input validation failed for tool '{tool_call.name}': {e.mess
- The injection template must contain the '{runtime_state}' pl
- Expected a 5-field cron expression, got {record.data.cron_ex
- Unsupported audio source type: {type(source)}
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/c1327fb1d39adefa.
Report an issue: GitHub.