Description
When a user opens the New Template → AI Assistant panel and sends a prompt, the response is always:
I encountered an error: Failed to fetch. Please try again.
This happens because no LLM API key (e.g. MISTRAL_API_KEY) has been stored in the user's Vault. The error is silent and gives the user no actionable guidance.
Root Cause
Bug 1 — Unhandled ValueError in the /generate route
In flowsint-api/app/api/routes/enricher_templates.py (lines 113–123), the generate call is wrapped in except ValidationError, but the LLM factory raises a ValueError (not a ValidationError) when the API key is missing:
# flowsint-core/src/flowsint_core/core/llm/factory.py, line 32
raise ValueError(
"API key not configured. Set MISTRAL_API_KEY environment variable or pass api_key argument."
)
Because ValueError is not caught, FastAPI returns an unhandled 500 Internal Server Error. In some cases this 500 response is missing CORS headers, so the browser throws TypeError: Failed to fetch with no useful detail — matching the symptom exactly.
Confirmed in API container logs:
ValueError: API key not configured. Set MISTRAL_API_KEY environment variable or pass api_key argument.
Bug 2 — No pre-flight key check in the AI Assistant UI
flowsint-app/src/components/templates/ai-chat-panel.tsx sends the prompt directly without first checking whether an LLM API key exists in the Vault. A /keys/exists/{key_name} endpoint already exists in the backend and could be used to show actionable guidance instead of the generic error.
Steps to Reproduce
- Start Flowsint with a fresh account (no Vault secrets configured)
- Navigate to Dashboard → Enrichers → New Template
- Open the AI Assistant panel
- Type any prompt and press Enter
- See:
I encountered an error: Failed to fetch. Please try again.
Expected Behavior
- The route handler should catch
ValueError and return a 422 with a clear message: "LLM API key not configured. Please add MISTRAL_API_KEY to your Vault."
- The AI Assistant panel should pre-check key existence on mount and show inline guidance if the key is missing, with a link to the Vault page
Suggested Fix
Backend (flowsint-api/app/api/routes/enricher_templates.py) — also catch ValueError:
try:
yaml_content = await service.generate(...)
except ValidationError as e:
raise HTTPException(status_code=422, detail=str(e))
except ValueError as e:
raise HTTPException(status_code=422, detail=str(e))
Frontend (flowsint-app/src/components/templates/ai-chat-panel.tsx) — check key existence on mount and show a warning banner:
useEffect(() => {
keyService.exists('MISTRAL_API_KEY').then(({ exists }) => {
if (!exists) setKeyMissing(true)
})
}, [])
Environment
- Flowsint Docker prod build
- Default LLM provider:
mistral (env default, no override set)
- OS: Windows 11, Docker Desktop v4.76.0
Related Files
flowsint-api/app/api/routes/enricher_templates.py — missing ValueError catch
flowsint-core/src/flowsint_core/core/llm/factory.py — raises ValueError on missing key
flowsint-core/src/flowsint_core/core/services/template_generator_service.py — calls _get_llm_provider without catching
flowsint-app/src/components/templates/ai-chat-panel.tsx — no pre-flight key check
flowsint-app/src/api/key-service.ts — existing exists() helper available for the pre-check
Description
When a user opens the New Template → AI Assistant panel and sends a prompt, the response is always:
This happens because no LLM API key (e.g.
MISTRAL_API_KEY) has been stored in the user's Vault. The error is silent and gives the user no actionable guidance.Root Cause
Bug 1 — Unhandled
ValueErrorin the/generaterouteIn
flowsint-api/app/api/routes/enricher_templates.py(lines 113–123), thegeneratecall is wrapped inexcept ValidationError, but the LLM factory raises aValueError(not aValidationError) when the API key is missing:Because
ValueErroris not caught, FastAPI returns an unhandled 500 Internal Server Error. In some cases this 500 response is missing CORS headers, so the browser throwsTypeError: Failed to fetchwith no useful detail — matching the symptom exactly.Confirmed in API container logs:
Bug 2 — No pre-flight key check in the AI Assistant UI
flowsint-app/src/components/templates/ai-chat-panel.tsxsends the prompt directly without first checking whether an LLM API key exists in the Vault. A/keys/exists/{key_name}endpoint already exists in the backend and could be used to show actionable guidance instead of the generic error.Steps to Reproduce
I encountered an error: Failed to fetch. Please try again.Expected Behavior
ValueErrorand return a 422 with a clear message:"LLM API key not configured. Please add MISTRAL_API_KEY to your Vault."Suggested Fix
Backend (
flowsint-api/app/api/routes/enricher_templates.py) — also catchValueError:Frontend (
flowsint-app/src/components/templates/ai-chat-panel.tsx) — check key existence on mount and show a warning banner:Environment
mistral(env default, no override set)Related Files
flowsint-api/app/api/routes/enricher_templates.py— missingValueErrorcatchflowsint-core/src/flowsint_core/core/llm/factory.py— raisesValueErroron missing keyflowsint-core/src/flowsint_core/core/services/template_generator_service.py— calls_get_llm_providerwithout catchingflowsint-app/src/components/templates/ai-chat-panel.tsx— no pre-flight key checkflowsint-app/src/api/key-service.ts— existingexists()helper available for the pre-check