{"record":{"id":"9b697f7d3abf0d39","repo":"lfnovo/open-notebook","slug":"final-answer-model-ask-request-final-answer-model","errorCode":null,"errorMessage":"Final answer model {ask_request.final_answer_model} not found","messagePattern":"Final answer model (.+?) not found","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"api/routers/search.py","lineNumber":143,"sourceCode":"    \"\"\"Ask the knowledge base a question using AI models.\"\"\"\n    try:\n        # Validate models exist\n        strategy_model = await Model.get(ask_request.strategy_model)\n        answer_model = await Model.get(ask_request.answer_model)\n        final_answer_model = await Model.get(ask_request.final_answer_model)\n\n        if not strategy_model:\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Strategy model {ask_request.strategy_model} not found\",\n            )\n        if not answer_model:\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Answer model {ask_request.answer_model} not found\",\n            )\n        if not final_answer_model:\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Final answer model {ask_request.final_answer_model} not found\",\n            )\n\n        # Check if embedding model is available\n        if not await model_manager.get_embedding_model():\n            raise HTTPException(\n                status_code=400,\n                detail=\"Ask feature requires an embedding model. Please configure one in the Models section.\",\n            )\n\n        # For streaming response\n        return StreamingResponse(\n            stream_ask_response(\n                ask_request.question, strategy_model, answer_model, final_answer_model\n            ),\n            media_type=\"text/event-stream\",\n            headers={","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/search.py#L125-L161","documentation":"400 from /api/search/ask when the final answer model ID does not exist in the database. This model produces the final polished answer of the ask pipeline.","triggerScenarios":"POST /api/search/ask with a final_answer_model ID that has no corresponding models row.","commonSituations":"Deleted or renamed models, stale persisted request payloads from the UI.","solutions":["Validate all three model IDs against GET /api/models before asking","Re-select models in the UI so fresh IDs are sent"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const valid = models.some(m => m.id === req.final_answer_model);\nif (!valid) req.final_answer_model = getDefault('final_answer');","typeGuard":"const isKnownModelId = (id: string, models: Model[]) => models.some(m => m.id === id);","tryCatchPattern":"catch (e) { if (e.status === 400 && e.detail.includes('Final answer model')) refreshModelSelection(); }","preventionTips":["Validate every model ID; clean up references when deleting models"],"tags":["ask","model-not-found","http-400","final-answer-model"],"backgroundTag":"referenced-model-missing","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}