{"record":{"id":"9d9ae0d02434fd68","repo":"mudler/LocalAI","slug":"unknown-builtin-reward-function-name-availabl","errorCode":null,"errorMessage":"Unknown builtin reward function '{name}'. Available: {available}","messagePattern":"Unknown builtin reward function '(.+?)'\\. Available: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/python/trl/reward_functions.py","lineNumber":222,"sourceCode":"    \"\"\"\n    if isinstance(specs_json, str):\n        specs = json.loads(specs_json)\n    else:\n        specs = specs_json\n\n    if not isinstance(specs, list):\n        raise ValueError(\"reward_funcs must be a JSON array of reward function specs\")\n\n    reward_funcs = []\n    for spec in specs:\n        spec_type = spec.get(\"type\", \"builtin\")\n        name = spec.get(\"name\", \"\")\n        params = spec.get(\"params\", {})\n\n        if spec_type == \"builtin\":\n            if name not in BUILTIN_REGISTRY:\n                available = \", \".join(sorted(BUILTIN_REGISTRY.keys()))\n                raise ValueError(\n                    f\"Unknown builtin reward function '{name}'. Available: {available}\"\n                )\n            func = BUILTIN_REGISTRY[name]\n            if params:\n                # Convert string params to appropriate types\n                typed_params = {}\n                for k, v in params.items():\n                    try:\n                        typed_params[k] = int(v)\n                    except (ValueError, TypeError):\n                        try:\n                            typed_params[k] = float(v)\n                        except (ValueError, TypeError):\n                            typed_params[k] = v\n                func = functools.partial(func, **typed_params)\n            reward_funcs.append(func)\n\n        elif spec_type == \"inline\":","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/python/trl/reward_functions.py#L204-L240","documentation":"Reward specs with type 'builtin' must name a function in BUILTIN_REGISTRY (format_reward, reasoning_accuracy_reward, length_reward, etc.). Unknown names get a ValueError enumerating the available builtins, which acts as discoverable inline documentation of the registry.","triggerScenarios":"spec name='accuracy' (not registered); typos like 'format-reward' or 'Format_Reward'; referencing a builtin added in a newer backend version.","commonSituations":"Guessing builtin names instead of checking the registry; version skew between backend and client docs; renaming drift after upgrading.","solutions":["Read the 'Available: ...' list in the error message and use one of those exact names.","Fix casing/underscores to match the registry (e.g. 'format_reward').","If you truly need custom logic, switch the spec to type 'inline' (requires the opt-in env var) instead of a nonexistent builtin."],"exampleFix":"# before\n{\"type\": \"builtin\", \"name\": \"format-reward\"}\n# after\n{\"type\": \"builtin\", \"name\": \"format_reward\"}","handlingStrategy":"validation","validationCode":"BUILTIN_NAMES = {\"format_reward\", \"reasoning_accuracy_reward\", \"length_reward\"}  # sync with registry\n\ndef builtin_known(name: str) -> bool:\n    return name in BUILTIN_NAMES","typeGuard":null,"tryCatchPattern":"try:\n    build_reward_functions(specs)\nexcept ValueError as e:\n    if \"Available:\" in str(e):\n        # parse the names from the message and suggest the closest\n        raise ConfigError(str(e)) from e\n    raise","preventionTips":["Fetch/track BUILTIN_REGISTRY keys as part of client configuration.","Use difflib.get_close_matches client-side to catch typos before sending.","Pin backend and client versions together."],"tags":["trl","reward-functions","registry","validation","localai"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}