{"record":{"id":"40f0ec3c04a6f88f","repo":"affaan-m/ECC","slug":"template-content-must-be-a-non-empty-string","errorCode":null,"errorMessage":"Template content must be a non-empty string","messagePattern":"Template content must be a non-empty string","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llm/prompt/templates/__init__.py","lineNumber":14,"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.\"\"\"\n    _TEMPLATE_REGISTRY.clear()\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/src/llm/prompt/templates/__init__.py#L1-L32","documentation":"The second check in _validate_template_input(): when a template argument is supplied it must be a non-empty, non-whitespace string. Fires from register_template() if you pass '' or '   ' or a non-string as the template body.","triggerScenarios":"Calling register_template('x', ''); register_template('x', '   '); passing a template loaded from an empty file; passing None accidentally is fine (it is the sentinel for 'no template'), but '' or whitespace is not.","commonSituations":"Reading template bodies from disk where a file was empty; a config field that defaulted to '' instead of None; trimming logic that reduced a placeholder to whitespace.","solutions":["Skip registration when the template body is empty rather than calling register_template with ''.","Load template files with a guard: body = path.read_text().strip(); if not body: skip.","Use None (not '') as the 'no value' sentinel when threading optional templates."],"exampleFix":"# before\nbody = Path(path).read_text() if path else ''\nregister_template(name, body)\n\n# after\nbody = Path(path).read_text().strip() if path else ''\nif body:\n    register_template(name, body)","handlingStrategy":"validation","validationCode":"from pathlib import Path\nfrom llm.prompt.templates import register_template\n\ndef safe_register_from_file(name: str, path: Path) -> None:\n    body = path.read_text().strip() if path.exists() else ''\n    if body:\n        register_template(name, body)","typeGuard":"def is_valid_template_body(body: object) -> bool:\n    return isinstance(body, str) and bool(body.strip())","tryCatchPattern":"from llm.prompt.templates import register_template\ntry:\n    register_template(name, body)\nexcept ValueError:\n    pass  # skip empty body","preventionTips":["Use None (not '') as the sentinel for 'no template'.","Guard file-loaded templates with a non-empty check before registering.","Document that whitespace-only bodies are rejected the same as empty strings."],"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"}