{"record":{"id":"ec019805ed6a15ba","repo":"ZhuLinsen/daily_stock_analysis","slug":"validation-failed","errorCode":"validation_failed","errorMessage":"System configuration validation failed","messagePattern":"System configuration validation failed","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"api/v1/endpoints/system_config.py","lineNumber":247,"sourceCode":"        400: {\"description\": \"Validation failed\", \"model\": SystemConfigValidationErrorResponse},\n        500: {\"description\": \"Internal server error\", \"model\": ErrorResponse},\n    },\n    summary=\"Preview generation backend status\",\n    description=\"Run a side-effect-free cheap check against unsaved settings draft values.\",\n)\ndef preview_generation_backend_status(\n    request: GenerationBackendStatusPreviewRequest,\n    service: SystemConfigService = Depends(get_system_config_service),\n) -> GenerationBackendStatusResponse:\n    \"\"\"Return generation backend status for unsaved draft values.\"\"\"\n    try:\n        payload = service.preview_generation_backend_status(\n            items=[item.model_dump() for item in request.items],\n            mask_token=request.mask_token,\n        )\n        return GenerationBackendStatusResponse.model_validate(payload)\n    except ConfigValidationError as exc:\n        raise HTTPException(\n            status_code=400,\n            detail={\n                \"error\": \"validation_failed\",\n                \"message\": \"System configuration validation failed\",\n                \"issues\": exc.issues,\n            },\n        )\n    except Exception as exc:\n        logger.error(\"Failed to preview generation backend status: %s\", exc, exc_info=True)\n        raise HTTPException(\n            status_code=500,\n            detail={\n                \"error\": \"internal_error\",\n                \"message\": \"Failed to preview generation backend status\",\n            },\n        )\n\n","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/api/v1/endpoints/system_config.py#L229-L265","documentation":"Raised by POST /system/config/generation-backends/status/preview when service.preview_generation_backend_status raises ConfigValidationError while checking unsaved draft values. Returns 400 'validation_failed' with the structured exc.issues list attached — this is a functional validation response, not a server fault.","triggerScenarios":"Submitting draft generation backend items (e.g. a backend entry with an empty API key, invalid model name, or unknown backend_id) to the preview endpoint; the service validates drafts before computing status.","commonSituations":"User editing backend config in the settings UI and previewing before save; automation posting incomplete draft payloads; masked token misuse (wrong mask_token) when editing secrets.","solutions":["Read the 'issues' array in the 400 body — each entry identifies which draft item field failed","Fix the flagged fields in the request items and re-POST the preview","Do not treat this as retryable; it is deterministic input validation"],"exampleFix":"// before\nconst res = await fetch(url, {method:'POST', body: JSON.stringify({items: [{backend_id: '', ...}]})});\n// after\nconst res = await fetch(url, {method:'POST', body: JSON.stringify({items: [{backend_id: 'openai', ...}]})});\nif (res.status === 400) { const {detail} = await res.json(); showIssues(detail.issues); }","handlingStrategy":"validation","validationCode":"// Validate drafts minimally client-side before preview:\nitems.every(i => i.backend_id && typeof i === 'object')","typeGuard":"function hasValidationIssues(d) {\n  return d?.detail?.error === 'validation_failed' && Array.isArray(d.detail.issues);\n}","tryCatchPattern":"const body = await res.json();\nif (res.status === 400 && body.detail?.error === 'validation_failed') {\n  showIssues(body.detail.issues); // structured, per-field\n}","preventionTips":["Always render the issues array instead of a generic message","Run preview before save/smoke-test to catch invalid drafts cheaply"],"tags":["api","config","validation","llm-backend"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}