{"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/8321021c54d670126ce3b2969d5deb880b4b0c2a/src/llm/prompt/templates/__init__.py#L1-L30","documentation":"_validate_template_input is the shared guard for the prompt template registry. It rejects any name that is not a non-empty, non-whitespace string, raising ValueError before the registry is mutated. deregister_template passes template=None, so only the name check applies there.","triggerScenarios":"register_template(None, t), register_template('', t), register_template('   ', t), deregister_template(42) — any call where name is non-string, empty, or whitespace-only.","commonSituations":"Template names built dynamically from config that resolves to None; reading template names from JSON/YAML where missing keys become empty; passing an enum/int instead of str.","solutions":["Pass a non-empty string as the template name","Strip/validate the name at the call site before registering","Fix the config/lookup that produced a None or empty name","Coerce non-strings with str() only if the value is genuinely a name"],"exampleFix":"// before\nregister_template(cfg.get('template_name'), tpl)\n// after\nname = (cfg.get('template_name') or '').strip()\nif not name:\n    raise ValueError('template_name is required in config')\nregister_template(name, tpl)","handlingStrategy":"validation","validationCode":"def valid_template_name(name) -> bool:\n    return isinstance(name, str) and bool(name.strip())","typeGuard":"def is_nonempty_str(v: object) -> TypeGuard[str]:\n    return isinstance(v, str) and bool(v.strip())","tryCatchPattern":"try:\n    register_template(name, tpl)\nexcept ValueError as e:\n    if 'name must be a non-empty string' in str(e):\n        logger.error('invalid template name %r', name)\n        raise","preventionTips":["Require template names in config files; fail fast when absent","Strip and validate names at config-load time","Keep template names as typed constants rather than dynamic strings"],"tags":["value-error","validation","registry","template"],"backgroundTag":"empty-required-field","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}