{"record":{"id":"9c23b43d8688775b","repo":"mudler/LocalAI","slug":"unknown-reward-function-type-spec-type-use-b","errorCode":null,"errorMessage":"Unknown reward function type '{spec_type}'. Use 'builtin' or 'inline'","messagePattern":"Unknown reward function type '(.+?)'\\. Use 'builtin' or 'inline'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/python/trl/reward_functions.py","lineNumber":256,"sourceCode":"            reward_funcs.append(func)\n\n        elif spec_type == \"inline\":\n            if not _inline_rewards_allowed():\n                raise ValueError(\n                    f\"Inline reward function '{name}' rejected: inline reward code \"\n                    f\"executes arbitrary Python and is disabled by default. Set \"\n                    f\"{ALLOW_INLINE_ENV}=true on the backend to enable it (only on a \"\n                    f\"trusted, access-controlled instance), or use a builtin reward \"\n                    f\"function instead.\"\n                )\n            code = spec.get(\"code\", \"\")\n            if not code.strip():\n                raise ValueError(f\"Inline reward function '{name}' has no code\")\n            func = compile_inline_reward(name, code)\n            reward_funcs.append(func)\n\n        else:\n            raise ValueError(f\"Unknown reward function type '{spec_type}'. Use 'builtin' or 'inline'\")\n\n    return reward_funcs\n","sourceCodeStart":238,"sourceCodeEnd":259,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/python/trl/reward_functions.py#L238-L259","documentation":"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.","triggerScenarios":"spec = {'type':'custom','name':...}; 'type':'BuiltIn' with wrong case; future spec kinds not understood by this backend version.","commonSituations":"Clients inventing new spec types; schema drift after an API update; copy-paste from docs describing a newer version.","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."],"exampleFix":"# before\n{\"type\": \"custom\", \"name\": \"format_reward\"}\n# after\n{\"type\": \"builtin\", \"name\": \"format_reward\"}","handlingStrategy":"type-guard","validationCode":"VALID_TYPES = {\"builtin\", \"inline\"}\n\ndef spec_type_valid(spec: dict) -> bool:\n    return spec.get(\"type\", \"builtin\") in VALID_TYPES","typeGuard":"def is_valid_reward_spec(spec) -> bool:\n    return (\n        isinstance(spec, dict)\n        and spec.get(\"type\", \"builtin\") in {\"builtin\", \"inline\"}\n        and isinstance(spec.get(\"name\", \"\"), str)\n    )","tryCatchPattern":"try:\n    build_reward_functions(specs)\nexcept ValueError as e:\n    if \"Unknown reward function type\" in str(e):\n        for s in specs:\n            s.setdefault(\"type\", \"builtin\")\n        retry()\n    raise","preventionTips":["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."],"tags":["trl","reward-functions","validation","enum","localai"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}