{"record":{"id":"2433e7b44be841b8","repo":"bytedance/deer-flow","slug":"input-text-exceeds-max-chars-characters","errorCode":null,"errorMessage":"Input text exceeds {max_chars} characters","messagePattern":"Input text exceeds (.+?) characters","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"backend/app/gateway/routers/input_polish.py","lineNumber":84,"sourceCode":"    body: InputPolishRequest,\n    request: Request,\n    config: AppConfig = Depends(get_config),\n) -> InputPolishResponse:\n    del request  # Required by the auth decorator.\n\n    if not config.input_polish.enabled:\n        raise HTTPException(status_code=404, detail=\"Input polishing is disabled\")\n\n    # Validate the same normalized view of the input that we send to the model,\n    # so the user-facing length boundary and the model input cannot disagree\n    # (e.g. a padded draft passing the check but arriving with stray whitespace).\n    text = body.text.strip()\n    if not text:\n        raise HTTPException(status_code=400, detail=\"Input text is required\")\n\n    max_chars = config.input_polish.max_chars\n    if len(text) > max_chars:\n        raise HTTPException(status_code=400, detail=f\"Input text exceeds {max_chars} characters\")\n\n    model_name = config.input_polish.model_name\n    try:\n        raw = await run_oneshot_llm(\n            system_instruction=_build_system_instruction(),\n            user_content=_build_user_content(text, body.locale),\n            run_name=\"input_polish\",\n            app_config=config,\n            model_name=model_name,\n            thread_id=body.thread_id,\n        )\n        rewritten = _clean_rewritten_text(raw)\n    except Exception as exc:\n        logger.exception(\"Failed to polish input: thread_id=%s err=%s\", body.thread_id, exc)\n        raise HTTPException(status_code=503, detail=\"Failed to polish input\") from exc\n\n    if not rewritten:\n        raise HTTPException(status_code=503, detail=\"Failed to polish input\")","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/app/gateway/routers/input_polish.py#L66-L102","documentation":"Raised by POST /input-polish with status 400 when the trimmed text length exceeds config.input_polish.max_chars. The limit is enforced server-side on the same normalized string sent to the model, keeping the user-facing boundary and the LLM input consistent. The response detail includes the configured max so clients can display it.","triggerScenarios":"Polishing a very long draft (e.g. pasted document) beyond the configured cap; client maxlength differing from server max_chars; lowering max_chars in config while the UI still allows longer input.","commonSituations":"Users pasting whole files into the composer; environments where operators tune max_chars down for cost; frontend using a stale default limit after a config change.","solutions":["Enforce the same limit client-side (maxLength on the textarea / pre-check trim().length) and show a character counter.","Split very long drafts or summarize before polishing instead of sending as-is.","If longer input is genuinely needed, raise input_polish.max_chars in config.yaml."],"exampleFix":"// before\nawait polish({ text: draft }); // 12k chars -> 400\n\n// after\nconst MAX = await getInputPolishLimits(); // exposes max_chars\nif (draft.trim().length > MAX) {\n  showWarning(`Draft exceeds ${MAX} characters — trim before polishing`);\n} else {\n  await polish({ text: draft.trim() });\n}","handlingStrategy":"validation","validationCode":"const text = draft.trim();\nif (text.length > MAX_CHARS) { warn(`Limit ${MAX_CHARS} chars (you have ${text.length})`); return; }\nawait polish({ text });","typeGuard":"const withinPolishLimit = (s: string, max: number) => s.trim().length <= max;","tryCatchPattern":null,"preventionTips":["Mirror server max_chars in the client (fetch it, don't hardcode)","Show a live character counter on long drafts","Split or summarize oversized pastes before polishing"],"tags":["http-400","validation","input-polish","length-limit"],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}