zylon-ai/private-gpt · error · ValueError

Invalid ToolValidationMode: {mode_str}

Error message

Invalid ToolValidationMode: {mode_str}

What it means

ValueError raised by ToolValidationMode.from_str when the input string (lowercased) is neither 'eager' nor 'lazy'. It is a strict parser for the tool validation mode enum.

Source

Thrown at private_gpt/components/tools/types.py:20


class ToolValidationMode(enum.StrEnum):
    EAGER = "eager"
    LAZY = "lazy"

    def __str__(self) -> str:
        return self.value

    @classmethod
    def from_str(cls, mode_str: str) -> "ToolValidationMode":
        """Create a ToolValidationMode from a string."""
        mode_str = mode_str.lower()
        if mode_str == "eager":
            return cls.EAGER
        elif mode_str == "lazy":
            return cls.LAZY
        else:
            raise ValueError(f"Invalid ToolValidationMode: {mode_str}")

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Use exactly 'eager' or 'lazy' (case-insensitive) as the validation mode string
  2. Normalize/whitelist user input before calling from_str: value.lower().strip() and check membership in {'eager','lazy'}
  3. Send the enum value directly in typed clients instead of free-form strings

Example fix

# before
mode = ToolValidationMode.from_str(user_input)
# after
_normalized = user_input.strip().lower()
if _normalized not in {"eager", "lazy"}:
    raise ValueError(f"validation_mode must be 'eager' or 'lazy', got {user_input!r}")
mode = ToolValidationMode.from_str(_normalized)
Defensive patterns

Strategy: validation

Validate before calling

_ALLOWED = {"eager", "lazy"}

def parse_validation_mode(raw: str) -> "ToolValidationMode":
    normalized = raw.strip().lower()
    if normalized not in _ALLOWED:
        raise ValueError(f"validation mode must be one of {sorted(_ALLOWED)}, got {raw!r}")
    return ToolValidationMode.from_str(normalized)

Type guard

def is_valid_validation_mode(raw: str) -> bool:
    return isinstance(raw, str) and raw.strip().lower() in {"eager", "lazy"}

Try / catch

try:
    mode = ToolValidationMode.from_str(mode_str)
except ValueError:
    # default to a safe mode or return a 4xx to the caller with allowed values

Prevention

When it happens

Trigger: Calling ToolValidationMode.from_str with values like 'none', 'off', 'strict', 'true', or an empty string; feeding an unvalidated user/UI string straight into the parser; config field tool_config.validation_mode set to an unsupported word.

Common situations: API clients sending arbitrary strings for validation mode; older configs using a previous name for the same mode; boolean-ish values ('on'/'off') used where the enum expects eager/lazy.

Related errors


AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15). Data as JSON: /api/errors/a16e91a27ae68b2c. Report an issue: GitHub.