{"record":{"id":"b12243596d32a17c","repo":"BerriAI/litellm","slug":"join-finish-reasons","errorCode":null,"errorMessage":"\"; \".join(finish_reasons)","messagePattern":"\"; \"\\.join\\(finish_reasons\\)","errorType":"http","errorClass":"BedrockError","httpStatus":400,"severity":"error","filePath":"litellm/llms/bedrock/image_generation/amazon_stability3_transformation.py","lineNumber":98,"sourceCode":"\n        No OpenAI params are mapped for Stability 3, so directly return the optional_params\n        \"\"\"\n        return optional_params\n\n    @classmethod\n    def transform_response_dict_to_openai_response(\n        cls, model_response: ImageResponse, response_dict: dict\n    ) -> ImageResponse:\n        \"\"\"\n        Transform the response dict to the OpenAI response\n        \"\"\"\n\n        stability_3_response: Final = AmazonStability3TextToImageResponse(**response_dict)\n\n        finish_reasons = stability_3_response.get(\"finish_reasons\", [])\n        finish_reasons = [reason for reason in finish_reasons if reason]\n        if len(finish_reasons) > 0:\n            raise BedrockError(status_code=400, message=\"; \".join(finish_reasons))\n\n        openai_images: Final[list[Image]] = []\n        for _img in stability_3_response.get(\"images\", []):\n            openai_images.append(Image(b64_json=_img))\n\n        model_response.data = openai_images\n        return model_response\n\n    @classmethod\n    def cost_calculator(\n        cls,\n        model: str,\n        image_response: ImageResponse,\n        size: str | None = None,\n        optional_params: dict | None = None,\n    ) -> float:\n        get_model_info: Final = get_cached_model_info()\n        model_info: Final = get_model_info(","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/image_generation/amazon_stability3_transformation.py#L80-L116","documentation":"After a Stability 3 image request on Bedrock returns 200, the response is parsed into AmazonStability3TextToImageResponse. If finish_reasons[] contains any non-empty entries, Bedrock reported generation failures and litellm raises BedrockError(status_code=400) with the reasons joined by '; '. This is a server-side content- or input-quality failure delivered in a successful HTTP response.","triggerScenarios":"Calling litellm.image_generation() with model='bedrock/stability.stable-image-core-1:0' (or ultra/core variants) where Stability rejects the prompt (content filter) or the request has invalid parameters; finish_reasons like 'Invalid prompt: Input text prompt contains unsafe content' come back non-empty.","commonSituations":"Prompts with NSFW/violent content triggering Stability's filter, negative-prompt misuse, aspect_ratio/seed-strength values Stability rejects, or intermittent safety-filter false positives.","solutions":["Read the joined finish_reasons in the BedrockError message — it states the exact cause (usually content filter or invalid input).","Rephrase the prompt to remove flagged terms; try a simpler prompt to confirm the filter is the cause.","Check/adjust Stability-specific params (aspect_ratio, seed, negative_prompt) against the Stability 3 API spec.","If the filter is a false positive, switch to a different image model (e.g. Nova Canvas / Titan Image)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.exceptions import BedrockError\n\ntry:\n    resp = litellm.image_generation(model=\"bedrock/stability.stable-image-core-1:0\", prompt=p)\nexcept BedrockError as e:\n    if e.status_code == 400 and \"finish_reason\" not in str(e):\n        raise  # unrelated 400\n    log.warning(\"Stability rejected prompt: %s\", e.message)\n    return fallback_prompt_or_model(p)","preventionTips":["Wrap Stability image calls in BedrockError handling — content-filter failures arrive as 400 with finish_reason text despite HTTP 200 semantics upstream.","Keep a moderated-prompt precheck or a sanitizing step for user-supplied prompts.","Have a second model configured as fallback for filtered prompts."],"tags":["bedrock","stability","content-filter","image-generation","finish-reason"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}