# Function call with finish\_reason of stop

**URL:** <https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226>\
**Category:** Feedback\
**Created:** [October 17, 2023, 2:50pm UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226 "2023-10-17T14:50:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![werner1](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/werner1/32/199131_2.png) [@werner1](https://community.openai.com/u/werner1)\
**Post date:** [October 17, 2023, 2:50pm UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/1 "2023-10-17T14:50:58Z")

</div>

We are receiving some responses from the api with finish\_reason of “stop” when the model is calling a function.  
Has anyone else experienced this?

 ![image](https://us1.discourse-cdn.com/openai1/original/3X/5/2/52a7566bd3d747aa2ec71dd01dd07efaec645744.png)

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [October 17, 2023, 3:26pm UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/2 "2023-10-17T15:26:41Z")

</div>

Nope, over and over a finish reason:

```auto
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "function_call": {
          "name": "submit_iso_datetime",
          "arguments": "{\n \"iso8601_datetime\": \"2023-02-06T16:33:00Z\"\n}"
        }
      },
      "finish_reason": "function_call"
    }

```

I made plenty of trials also trying to stop any of three models from producing the certainty of multi-line JSON by function descriptions, without success (except once at temperature 2.0, which can also produce copious server 500 errors from malformed function outputs), all without a “stop” being produced in any case.

You can use top\_p = 0.4 to reduce the chance of the wrong “finish” output special token being produced.

---

<div class="post-metadata">

**Author:** ![Foxalabs](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/foxalabs/32/738355_2.png) [@Foxalabs](https://community.openai.com/u/Foxalabs)\
**Post date:** [October 17, 2023, 3:43pm UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/3 "2023-10-17T15:43:20Z")

</div>

Hi,

Can you post a copy of the prompt that produced this finish reason?

---

<div class="post-metadata">

**Author:** ![merefield](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/merefield/32/14812_2.png) [@merefield](https://community.openai.com/u/merefield)\
**Post date:** [June 7, 2024, 12:37pm UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/4 "2024-06-07T12:37:05Z")

</div>

I can corroborate this.

Just happened to me several times with gpt 3.5 _and_ `gpt-4o`.

One piece of important information, it seems to happen when you say a tool choice is `required`, ie:

`"tool_choice" : "required"`

That’s really not good though.

In that circumstance it should still have a ‘tool\_calls’ `finish_reason`.

If however, I force a _specific_ function the issue is not present.

This looks like a _bug_! 🪲

It is _certainly_ _not_ desirable and definitely _inconsistent_ and needs to be handled with messy code!

I going to have to put a horrible workaround in code for the time being 😢

ie something like this:

(saving you from messy destructuring code!)

```auto
if (['stop','length'].include?(finish_reason) && tools_calls.nil? 

```

and something like:

```auto
elsif finish_reason == 'tool_calls' || !tools_calls.nil? 

```

instead of just checking the finish reason only - yuk!

---

<div class="post-metadata">

**Author:** ![merefield](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/merefield/32/14812_2.png) [@merefield](https://community.openai.com/u/merefield)\
**Post date:** [June 10, 2024, 11:21am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/5 "2024-06-10T11:21:42Z")

</div>

@brianz-oai another couple of reports of [New API feature: forcing function calling via `tool_choice: "required"` - #13 by brianz-oai](https://community.openai.com/t/new-api-feature-forcing-function-calling-via-tool-choice-required/731488/13)

FYI I definitely would be happy to update my code to get rid of this cludge!

---

<div class="post-metadata">

**Author:** ![arpit1](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/arpit1/32/146875_2.png) [@arpit1](https://community.openai.com/u/arpit1)\
**Post date:** [June 18, 2024, 7:44pm UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/6 "2024-06-18T19:44:05Z")

</div>

Exact same issue with me. Seems to be a recent regression - I don’t have proof but IIRC I could get `finish_reason=tool_calls` even with `tool_choice=required` a few days ago [EDIT: apparently not]. At any rate, reverting to `tool_choice=auto` isn’t a good fix either (for me) - the model often ends up not returning tool calls (despite prompt instructing it to) or just adds a `tool_uses` json object in the `content` field of the message as a string (with some undocumented keys like `recipient_name`. Let me know if you’ve found a solution!

---

<div class="post-metadata">

**Author:** ![merefield](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/merefield/32/14812_2.png) [@merefield](https://community.openai.com/u/merefield)\
**Post date:** [August 14, 2024, 6:24am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/7 "2024-08-14T06:24:40Z")

</div>

What is the latest on this, is it fixed?

---

<div class="post-metadata">

**Author:** ![sps](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sps/32/7736_2.png) [@sps](https://community.openai.com/u/sps)\
**Post date:** [August 14, 2024, 9:07am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/9 "2024-08-14T09:07:27Z")

</div>

This is covered in the [function calling docs](https://platform.openai.com/docs/guides/function-calling/configuring-function-calling-behavior-using-the-tool_choice-parameter):

> By default, the model is configured to automatically select which functions to call, as determined by the tool\_choice: “auto” setting.
> 
> We offer three ways to customize the default behavior:
> 
> - To force the model to always call one or more functions, you can set tool\_choice: “required”. The model will then always select one or more function(s) to call. This is useful for example if you want the model to pick between multiple actions to perform next.
> - To force the model to call a specific function, you can set tool\_choice: {“type”: “function”, “function”: {“name”: “my\_function”}}.
> - To disable function calling and force the model to only generate a user-facing message, you can either provide no tools, or set tool\_choice: “none”.  
> Note that if you do either 1 or 2 (i.e. force the model to call a function) then the subsequent finish\_reason will be “stop” instead of being “tool\_calls”.

---

<div class="post-metadata">

**Author:** ![merefield](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/merefield/32/14812_2.png) [@merefield](https://community.openai.com/u/merefield)\
**Post date:** [August 14, 2024, 9:08am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/10 "2024-08-14T09:08:47Z")

</div>

Yes, but just because it is documented doesn’t mean it’s good 🙂

Please recall what staff said:

> [@New API feature: forcing function calling via \`tool\_choice: "required"\`](https://community.openai.com/t/new-api-feature-forcing-function-calling-via-tool-choice-required/731488/13):
>
> Fixing this now could potentially break some users’ integration, but we will almost certainly fix this when we release the next API version.

(FYI I would have posted there but the Topic was Closed)

So I guess: “when we release the next API version.” is a key part of this.

---

<div class="post-metadata">

**Author:** ![sps](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sps/32/7736_2.png) [@sps](https://community.openai.com/u/sps)\
**Post date:** [August 14, 2024, 10:22am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/11 "2024-08-14T10:22:42Z")

</div>

Agree. I meant that in both the cases where function call `required` or forced the response is certainly going to be function call.

---

<div class="post-metadata">

**Author:** ![merefield](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/merefield/32/14812_2.png) [@merefield](https://community.openai.com/u/merefield)\
**Post date:** [August 14, 2024, 10:31am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/12 "2024-08-14T10:31:53Z")

</div>

This is not helpful, did you even read the Topic and understand the issue, or just copy and paste from ChatGPT? `text-davinci-003` is even deprecated!

---

<div class="post-metadata">

**Author:** ![sebastian.wi](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sebastian.wi/32/451211_2.png) [@sebastian.wi](https://community.openai.com/u/sebastian.wi)\
**Post date:** [August 26, 2024, 12:28pm UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/13 "2024-08-26T12:28:16Z")

</div>

Definitely started happening this week, after months of working fine. I call the API like this:

```auto
    const params: OpenAI.Chat.ChatCompletionCreateParams = {
        model: "gpt-4-turbo-preview",
        messages: [
            {
                role: "user",
                content: text,
            },
        ],
        max_tokens: 4096,
tools: [
            {
                type: "function",
                function: {
                    name: "functionNameHere",
                    description:
                        "PromptHere",
                    parameters: SomeJsonHere,
                },

```

---

<div class="post-metadata">

**Author:** ![merefield](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/merefield/32/14812_2.png) [@merefield](https://community.openai.com/u/merefield)\
**Post date:** [September 29, 2024, 1:54pm UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/14 "2024-09-29T13:54:32Z")

</div>

Disagree @sebastian.wi but welcome to the community 👋

It’s been happening for a long time in the scenario I outline above.

But glad you’ve witnessed it.

This should be cleaned up in the API asap.

---

<div class="post-metadata">

**Author:** ![pedro.vicente](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/pedro.vicente/32/448863_2.png) [@pedro.vicente](https://community.openai.com/u/pedro.vicente)\
**Post date:** [November 20, 2024, 10:26pm UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/15 "2024-11-20T22:26:23Z")

</div>

Same behavior here. Definitely not the best user experience to have different finish reasons for different options of tool\_choice.

---

<div class="post-metadata">

**Author:** ![joan.segura](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/joan.segura/32/551663_2.png) [@joan.segura](https://community.openai.com/u/joan.segura)\
**Post date:** [February 13, 2025, 12:08am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/16 "2025-02-13T00:08:43Z")

</div>

fyi

just happened to me in a more than a year program that daily sends the same chat completion.

---

<div class="post-metadata">

**Author:** ![sam31](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sam31/32/511242_2.png) [@sam31](https://community.openai.com/u/sam31)\
**Post date:** [February 13, 2025, 1:46am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/17 "2025-02-13T01:46:11Z")

</div>

Appears this is occurring again. With one of my functions, it calls with reason stop, with the rest of my functions it calls with reason function\_call. Same function has been calling for months with no issue until today.

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [February 13, 2025, 2:21am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/18 "2025-02-13T02:21:01Z")

</div>

Can you report on the AI model that has been stealth-damaged?

Technically, either terminating a function output or terminating a response to a user involves the AI emitting an internal stop sequence token. Without a stop sequence closing the message, the output would continue forever.

However, of two options, It is writing the wrong token number that likely causes the anomaly, directly reported by the API. In cl100k-base, the difference between 100260 and 100265.

A `"strict":true` structured function call schema should improve the situation, enforcing what can be output after a function being sent is closed. Or rather, just evaluating what has been finally collected as tool\_call when a finish reason streaming chunk is reached, regardless of reason.

---

<div class="post-metadata">

**Author:** ![ansonlouis](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ansonlouis/32/551719_2.png) [@ansonlouis](https://community.openai.com/u/ansonlouis)\
**Post date:** [February 13, 2025, 4:40am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/19 "2025-02-13T04:40:52Z")

</div>

Also reporting seeing a finish reason of `stop` out of nowhere within the past couple of hours. Using gpt-4o with node sdk. I’m passing tools and not specifying a `tool_choice` (as has always worked properly for me)

---

<div class="post-metadata">

**Author:** ![anon16930695](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@anon16930695](https://community.openai.com/u/anon16930695)\
**Post date:** [February 13, 2025, 5:04am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/20 "2025-02-13T05:04:50Z")

</div>

I’d also like to report this issue. Function calling is now giving me a finish\_reason of `stop` instead of `tool_calls`

---

<div class="post-metadata">

**Author:** ![AlexSubbotin](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/alexsubbotin/32/551785_2.png) [@AlexSubbotin](https://community.openai.com/u/AlexSubbotin)\
**Post date:** [February 13, 2025, 7:42am UTC](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226/21 "2025-02-13T07:42:31Z")

</div>

We also started to get `finish_reason=stop` instead of `tool_calls` in some cases. I found that removing `Answer as concisely as possible` system message fixes the issue

[Next page](https://community.openai.com/t/function-call-with-finish-reason-of-stop/437226.md?page=2)
