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

  1. Skip registration when the template body is empty rather than calling register_template with ''.
  2. Load template files with a guard: body = path.read_text().strip(); if not body: skip.
  3. 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

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


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/40f0ec3c04a6f88f. Report an issue: GitHub.