alibaba/spring-ai-alibaba · error · IllegalArgumentException

模型缺少 provider

Error message

模型缺少 provider

What it means

FileModelConfigRepository.validateYamlModel() throws IllegalArgumentException "模型缺少 provider" ("model missing provider") when a YamlModel's provider field is null or blank. The provider identifies which model service (e.g. dashscope, openai, deepseek) serves the model and is required for building the runtime model client.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/FileModelConfigRepository.java:122

        Set<Long> ids = new HashSet<>();
        Set<String> names = new HashSet<>();
        for (YamlModel m : root.models) {
            validateYamlModel(m, ids, names);
            ModelConfigDO entity = toEntity(m);
            map.put(entity.getId(), entity);
        }
        return map;
    }
    
    private void validateYamlModel(YamlModel m, Set<Long> ids, Set<String> names) {
        if (m.id == null) {
            throw new IllegalArgumentException("模型缺少 id");
        }
        if (m.name == null || m.name.isBlank()) {
            throw new IllegalArgumentException("模型缺少 name");
        }
        if (m.provider == null || m.provider.isBlank()) {
            throw new IllegalArgumentException("模型缺少 provider");
        }
        if (m.modelName == null || m.modelName.isBlank()) {
            throw new IllegalArgumentException("模型缺少 modelName");
        }
        //        if (m.baseUrl == null || m.baseUrl.isBlank()) throw new IllegalArgumentException("模型缺少 baseUrl");
        if (m.apiKey == null || m.apiKey.isBlank()) {
            throw new IllegalArgumentException("模型缺少 apiKey");
        }
        if (!ids.add(m.id)) {
            throw new IllegalArgumentException("重复的模型 id: " + m.id);
        }
        if (!names.add(m.name)) {
            throw new IllegalArgumentException("重复的模型 name: " + m.name);
        }
        if (m.status == null) {
            m.status = 1;
        }
    }

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Add a valid `provider` (e.g. dashscope, openai) to every model entry in the YAML.
  2. Verify provider spelling matches the provider identifiers supported by the framework.
  3. Fix indentation so provider belongs to the intended model entry.
  4. Remove empty provider values (provider: "").

Example fix

// before (yaml)
  - id: 3
    name: gpt4
    modelName: gpt-4o
// after (yaml)
  - id: 3
    name: gpt4
    provider: openai
    modelName: gpt-4o
Defensive patterns

Strategy: validation

Validate before calling

models.forEach(m -> {
    if (m.provider == null || m.provider.isBlank()) throw new IllegalArgumentException("model '" + m.name + "' missing provider");
});

Type guard

static boolean hasProvider(YamlModel m) { return m != null && m.provider != null && !m.provider.isBlank(); }

Try / catch

try { repo = FileModelConfigRepository.loadFromFile(path); }
catch (IllegalArgumentException e) { log.error("Model config invalid: {}", e.getMessage()); throw new ConfigurationException(e); }

Prevention

When it happens

Trigger: Loading the models YAML with a model entry that lacks the `provider` key or has it blank, typically a hand-authored or partially copied entry.

Common situations: Writing a new model entry from scratch and forgetting provider; renaming provider keys during a config migration; YAML indentation nesting provider under the wrong entry.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/1b5a08e8270b047a. Report an issue: GitHub.