{"record":{"id":"a66e574104c550ff","repo":"affaan-m/ECC","slug":"template-name-must-be-a-non-empty-string","errorCode":null,"errorMessage":"Template name must be a non-empty string","messagePattern":"Template name must be a non-empty string","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llm/prompt/templates/__init__.py","lineNumber":12,"sourceCode":"\"\"\"Provider-specific prompt template helpers.\"\"\"\n\nfrom __future__ import annotations\n\n_TEMPLATE_REGISTRY: dict[str, str] = {}\nTEMPLATES = _TEMPLATE_REGISTRY\n\n\ndef _validate_template_input(name: str, template: str | None = None) -> None:\n    \"\"\"Validate template registry inputs before mutating the registry.\"\"\"\n    if not isinstance(name, str) or not name.strip():\n        raise ValueError(\"Template name must be a non-empty string\")\n    if template is not None and (not isinstance(template, str) or not template.strip()):\n        raise ValueError(\"Template content must be a non-empty string\")\n\n\ndef register_template(name: str, template: str) -> None:\n    \"\"\"Register or replace a named prompt template.\"\"\"\n    _validate_template_input(name, template)\n    _TEMPLATE_REGISTRY[name] = template\n\n\ndef deregister_template(name: str) -> None:\n    \"\"\"Remove a named prompt template if it is registered.\"\"\"\n    _validate_template_input(name)\n    _TEMPLATE_REGISTRY.pop(name, None)\n\n\ndef clear_templates() -> None:\n    \"\"\"Remove all registered prompt templates.\"\"\"","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/src/llm/prompt/templates/__init__.py#L1-L30","documentation":"_validate_template_input() guards register_template() and deregister_template(). If the name argument is not a string or is empty/whitespace-only, this ValueError fires before the registry is touched. It rejects None, non-string types, '', and '   '.","triggerScenarios":"Calling register_template('', tmpl); register_template(None, tmpl); register_template(123, tmpl); passing a name computed from a missing dict key that defaulted to None.","commonSituations":"Programmatic template registration from a config where a key was absent; a refactor that introduced an optional name parameter without a default.","solutions":["Ensure the name is a non-empty, stripped string before calling register_template/deregister_template.","Skip registration when the computed name is falsy rather than passing it through.","Add a unit test that asserts the validation message for '' and None."],"exampleFix":"# before\nname = config.get('template_name')  # may be None\nregister_template(name, content)\n\n# after\nname = (config.get('template_name') or '').strip()\nif name:\n    register_template(name, content)","handlingStrategy":"validation","validationCode":"from llm.prompt.templates import register_template\n\ndef safe_register(name: str, template: str) -> None:\n    if not isinstance(name, str) or not name.strip():\n        return  # skip rather than crash\n    register_template(name, template)","typeGuard":"def is_valid_template_name(name: object) -> bool:\n    return isinstance(name, str) and bool(name.strip())","tryCatchPattern":"from llm.prompt.templates import register_template\ntry:\n    register_template(name, template)\nexcept ValueError:\n    pass  # ignore invalid name","preventionTips":["Strip and check name before registering; skip registration when falsy.","Pull template names from a controlled enum or constants module.","Add unit tests covering '', None, and non-string inputs."],"tags":["validation","templates","registry","prompt"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}