lfnovo/open-notebook · warning · HTTPException

Strategy model {ask_request.strategy_model} not found

Error message

Strategy model {ask_request.strategy_model} not found

What it means

400 raised by the streaming /api/search/ask endpoint when the requested strategy model ID does not exist in the database (Model.get returned None). The strategy model is the LLM used to plan the ask pipeline.

Source

Thrown at api/routers/search.py:133

        from open_notebook.utils.error_classifier import classify_error

        _, user_message = classify_error(e)
        logger.error(f"Error in ask streaming: {str(e)}")
        error_data = {"type": "error", "message": user_message}
        yield f"data: {json.dumps(error_data)}\n\n"


@router.post("/search/ask")
async def ask_knowledge_base(ask_request: AskRequest):
    """Ask the knowledge base a question using AI models."""
    try:
        # Validate models exist
        strategy_model = await Model.get(ask_request.strategy_model)
        answer_model = await Model.get(ask_request.answer_model)
        final_answer_model = await Model.get(ask_request.final_answer_model)

        if not strategy_model:
            raise HTTPException(
                status_code=400,
                detail=f"Strategy model {ask_request.strategy_model} not found",
            )
        if not answer_model:
            raise HTTPException(
                status_code=400,
                detail=f"Answer model {ask_request.answer_model} not found",
            )
        if not final_answer_model:
            raise HTTPException(
                status_code=400,
                detail=f"Final answer model {ask_request.final_answer_model} not found",
            )

        # Check if embedding model is available
        if not await model_manager.get_embedding_model():
            raise HTTPException(
                status_code=400,

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Fetch current models via GET /api/models and use a valid strategy model ID
  2. Clear stale model selections in the frontend (Settings → default models)
  3. Create/restore the strategy model if it was accidentally deleted
Defensive patterns

Strategy: validation

Validate before calling

const models = await fetch('/api/models').then(r => r.json());
const valid = models.some(m => m.id === req.strategy_model);
if (!valid) req.strategy_model = getDefault('strategy');

Type guard

const isKnownModelId = (id: string, models: Model[]) => models.some(m => m.id === id);

Try / catch

catch (e) { if (e.status === 400 && e.detail.includes('Strategy model')) refreshModelSelection(); }

Prevention

When it happens

Trigger: POST /api/search/ask with a strategy_model ID that is not a row in the models table — deleted model, stale ID cached in the client, or wrong ID pasted from another instance.

Common situations: Model deleted after the frontend saved its ID, restoring a DB backup without models, multi-instance setups where model IDs differ.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/45faa045a8337cb2. Report an issue: GitHub.