affaan-m/ECC · error · ValueError
Template content must be a non-empty string
Error message
Template content must be a non-empty string
What it means
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.
Source
Thrown at src/llm/prompt/templates/__init__.py:14
"""Provider-specific prompt template helpers."""
from __future__ import annotations
_TEMPLATE_REGISTRY: dict[str, str] = {}
TEMPLATES = _TEMPLATE_REGISTRY
def _validate_template_input(name: str, template: str | None = None) -> None:
"""Validate template registry inputs before mutating the registry."""
if not isinstance(name, str) or not name.strip():
raise ValueError("Template name must be a non-empty string")
if template is not None and (not isinstance(template, str) or not template.strip()):
raise ValueError("Template content must be a non-empty string")
def register_template(name: str, template: str) -> None:
"""Register or replace a named prompt template."""
_validate_template_input(name, template)
_TEMPLATE_REGISTRY[name] = template
def deregister_template(name: str) -> None:
"""Remove a named prompt template if it is registered."""
_validate_template_input(name)
_TEMPLATE_REGISTRY.pop(name, None)
def clear_templates() -> None:
"""Remove all registered prompt templates."""
_TEMPLATE_REGISTRY.clear()
View on GitHub (pinned to 01e15490f0)
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.
Example fix
# before
body = Path(path).read_text() if path else ''
register_template(name, body)
# after
body = Path(path).read_text().strip() if path else ''
if body:
register_template(name, body) Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
from llm.prompt.templates import register_template
def safe_register_from_file(name: str, path: Path) -> None:
body = path.read_text().strip() if path.exists() else ''
if body:
register_template(name, body) Type guard
def is_valid_template_body(body: object) -> bool:
return isinstance(body, str) and bool(body.strip()) Try / catch
from llm.prompt.templates import register_template
try:
register_template(name, body)
except ValueError:
pass # skip empty body Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Template name must be a non-empty string
- Structured session targets require a non-empty string value
- Pass either config or PromptBuilder keyword options, not bot
- ECC_PROJECT_DIR must be a child path within /workspace.
- Unknown argument: ${arg}
AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13).
Data as JSON: /api/errors/40f0ec3c04a6f88f.
Report an issue: GitHub.