agentscope-ai/agentscope · error · ValueError

Invalid logging level: {level}. Must be one of 'INFO', 'DEBU

Error message

Invalid logging level: {level}. Must be one of 'INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL'.

What it means

This error is raised by agentscope's setup_logger when the `level` argument is not one of the five allowed logging level strings. The library validates eagerly because Python's logging module accepts other values (e.g. numeric levels or 'WARN') that agentscope does not want to support. Passing anything else aborts logger configuration.

Source

Thrown at src/agentscope/_logging.py:29

logger = logging.getLogger("as")


def setup_logger(
    level: str,
    filepath: str | None = None,
) -> None:
    """Set up the agentscope logger.

    Args:
        level (`str`):
            The logging level, chosen from "INFO", "DEBUG", "WARNING",
            "ERROR", "CRITICAL".
        filepath (`str | None`, optional):
            The filepath to save the logging output.
    """
    if level not in ["INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL"]:
        raise ValueError(
            f"Invalid logging level: {level}. Must be one of "
            f"'INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL'.",
        )
    logger.handlers.clear()
    logger.setLevel(level)
    handler = logging.StreamHandler()
    handler.setFormatter(logging.Formatter(_DEFAULT_FORMAT))
    logger.addHandler(handler)

    if filepath:
        handler = logging.FileHandler(filepath)
        handler.setFormatter(logging.Formatter(_DEFAULT_FORMAT))
        logger.addHandler(handler)

    logger.propagate = False


setup_logger("INFO")

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Pass an exact uppercase string: 'INFO', 'DEBUG', 'WARNING', 'ERROR', or 'CRITICAL'
  2. If the level comes from config/env, normalize it first: level = os.environ['LOG_LEVEL'].upper() and validate against the allowed list
  3. Do not pass logging module constants (e.g. logging.DEBUG); use the string form

Example fix

// before
setup_logger(level=logging.DEBUG)  # or level="debug"

# after
setup_logger(level="DEBUG")
Defensive patterns

Strategy: validation

Validate before calling

VALID_LEVELS = {"INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL"}
level = os.environ.get("LOG_LEVEL", "INFO").upper()
if level not in VALID_LEVELS:
    raise ValueError(f"Unsupported LOG_LEVEL {level!r}; choose from {sorted(VALID_LEVELS)}")
setup_logger(level=level)

Type guard

from typing import Literal
LogLevel = Literal["INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL"]

def is_log_level(v: str) -> TypeGuard[LogLevel]:
    return v in {"INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL"}

Prevention

When it happens

Trigger: Calling setup_logger(level=...) with a non-uppercase string ('info', 'warn'), a numeric level (logging.DEBUG = 10), 'WARN' (not in the list), or None.

Common situations: Copy-pasting logging constants from stdlib logging (logging.INFO), using lowercase level strings from env vars like LOG_LEVEL=debug without .upper(), or using 'WARN' which stdlib allows but agentscope rejects.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/78ea15b1f2f4a634. Report an issue: GitHub.