HKUDS/DeepTutor · error · ValueError

llm section must be a mapping

Error message

llm section must be a mapping

What it means

Pydantic 'before' validator on AppConfig.llm: the raw config's llm field is not a dict/mapping (null, list, or scalar), so it cannot be coerced into LLMConfig. Fires when the config file structure is wrong at the top level.

Solutions

  1. Fix the config file so llm is a mapping, e.g. llm: {model: ..., provider: ...}
  2. Validate config with a JSON schema before loading
  3. Check for YAML indentation errors that collapse llm into a scalar
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at deeptutor/config/schema.py:25 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/c5070cdc7c1a1edf. Report an issue: GitHub.

Appendix: source

Thrown at deeptutor/config/schema.py:25

    model: str
    provider: str = "openai"


class PathsConfig(BaseModel):
    user_data_dir: str
    knowledge_bases_dir: str
    user_log_dir: str


class AppConfig(BaseModel):
    llm: LLMConfig
    paths: PathsConfig

    @field_validator("llm", mode="before")
    @classmethod
    def ensure_llm(cls, v: Any) -> Dict[str, Any]:
        if not isinstance(v, dict):
            raise ValueError("llm section must be a mapping")
        if "model" not in v:
            raise ValueError("llm.model is required")
        return v


CURRENT_SCHEMA_VERSION = 1


def migrate_config(cfg: Dict[str, Any]) -> Dict[str, Any]:
    """
    No-op migration for now; placeholder for future versioned changes.
    """
    return cfg

View on GitHub (pinned to 3e82f13042)