set-openai changes the active provider before rejecting a missing model
A rejected set-openai command can replace the active provider
deepeval set-openai accepts an optional --model so it can reuse an OPENAI_MODEL_NAME that is already configured. If neither is available, it correctly reports that a model name is required. The problem is when that check happens: by the time the command raises BadParameter, it has already switched the active LLM provider and persisted the change.
That makes a failed configuration command change a working configuration. A user can start with Anthropic (or another provider), try set-openai without a model, see an error, and then find that the previous provider has been turned off.
Reproduction
In a clean configuration with no OPENAI_MODEL_NAME, select another LLM provider, then run the incomplete OpenAI command:
deepeval set-anthropic --model claude-sonnet-4-5 --save dotenv:.env.local
deepeval set-openai --save dotenv:.env.localThe second command exits with the expected message:
OpenAI model name is not set. Pass --model (or set OPENAI_MODEL_NAME).Compare the provider flags before and after that second command, either through get_settings() or in the persisted .deepeval/.deepeval and .env.local files. Before the command, USE_ANTHROPIC_MODEL is enabled. On the current main branch, the failed OpenAI command clears that selection and enables USE_OPENAI_MODEL, even though it did not establish a valid OpenAI model. This path does not require an API key or a model request.
Expected behavior
A missing effective model should be rejected before any provider switch. On exit code 2, the in-memory settings, the existing provider flags, and both persisted files should be byte-for-byte unchanged. If --model is present or OPENAI_MODEL_NAME is already configured, set-openai should continue to work as it does now.
Where the change occurs
set_openai_env() enters settings.edit(), calls switch_model_provider(), and leaves the edit context before it checks effective_model. switch_model_provider() clears the other flags and writes legacy provider keys while switching. The edit context also persists the settings on normal exit. The later BadParameter cannot undo those writes.
Validating the effective model immediately after loading settings, before entering settings.edit(), would keep this specific failure path side-effect free. A regression test can begin with an active non-OpenAI provider, snapshot the saved files, invoke the failing command, and assert both the error and the unchanged configuration.
Source: confident-ai/deepeval