mudler/LocalAI · error · ValueError
Unknown reward function type '{spec_type}'. Use 'builtin' or
Error message
Unknown reward function type '{spec_type}'. Use 'builtin' or 'inline' What it means
Each reward spec's 'type' field must be exactly 'builtin' or 'inline'; anything else ('function', 'custom', 'python', or a missing type that is not the defaulted 'builtin'... missing type defaults to builtin, so this fires only on explicitly wrong values) reaches the else branch and raises with the accepted values.
Source
Thrown at backend/python/trl/reward_functions.py:256
reward_funcs.append(func)
elif spec_type == "inline":
if not _inline_rewards_allowed():
raise ValueError(
f"Inline reward function '{name}' rejected: inline reward code "
f"executes arbitrary Python and is disabled by default. Set "
f"{ALLOW_INLINE_ENV}=true on the backend to enable it (only on a "
f"trusted, access-controlled instance), or use a builtin reward "
f"function instead."
)
code = spec.get("code", "")
if not code.strip():
raise ValueError(f"Inline reward function '{name}' has no code")
func = compile_inline_reward(name, code)
reward_funcs.append(func)
else:
raise ValueError(f"Unknown reward function type '{spec_type}'. Use 'builtin' or 'inline'")
return reward_funcs
View on GitHub (pinned to 44413a9d06)
Solutions
- Set type to 'builtin' for registry functions or 'inline' for code (with the env opt-in).
- Omit 'type' entirely when you mean builtin — it defaults to that.
- Upgrade the backend if you expected a newer spec kind.
Example fix
# before
{"type": "custom", "name": "format_reward"}
# after
{"type": "builtin", "name": "format_reward"} Defensive patterns
Strategy: type-guard
Validate before calling
VALID_TYPES = {"builtin", "inline"}
def spec_type_valid(spec: dict) -> bool:
return spec.get("type", "builtin") in VALID_TYPES Type guard
def is_valid_reward_spec(spec) -> bool:
return (
isinstance(spec, dict)
and spec.get("type", "builtin") in {"builtin", "inline"}
and isinstance(spec.get("name", ""), str)
) Try / catch
try:
build_reward_functions(specs)
except ValueError as e:
if "Unknown reward function type" in str(e):
for s in specs:
s.setdefault("type", "builtin")
retry()
raise Prevention
- Define a JSON schema enum for spec.type in the API contract.
- Omit type when using builtins (defaults apply).
- Validate specs client-side with a shared schema.
When it happens
Trigger: spec = {'type':'custom','name':...}; 'type':'BuiltIn' with wrong case; future spec kinds not understood by this backend version.
Common situations: Clients inventing new spec types; schema drift after an API update; copy-paste from docs describing a newer version.
Related errors
- Unsupported training method: {training_method}. Supported: s
- reward_funcs must be a JSON array of reward function specs
- Unknown builtin reward function '{name}'. Available: {availa
- Inline reward function '{name}' has no code
- GRPO requires at least one reward function. Specify reward_f
AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15).
Data as JSON: /api/errors/9c23b43d8688775b.
Report an issue: GitHub.