diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index bff0626a9..630ab608c 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -2158,14 +2158,17 @@ async def process_chat_payload(request, form_data, user, metadata, model): ) if "code_interpreter" in features and features["code_interpreter"]: - form_data["messages"] = add_or_update_user_message( - ( - request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE - if request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE != "" - else DEFAULT_CODE_INTERPRETER_PROMPT - ), - form_data["messages"], - ) + # Skip XML-tag prompt injection when native FC is enabled — + # execute_code will be injected as a builtin tool instead + if metadata.get("params", {}).get("function_calling") != "native": + form_data["messages"] = add_or_update_user_message( + ( + request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE + if request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE != "" + else DEFAULT_CODE_INTERPRETER_PROMPT + ), + form_data["messages"], + ) tool_ids = form_data.pop("tool_ids", None) files = form_data.pop("files", None)