A finish reason is the response field that identifies why text generation ended or why an API returned a particular output. Tracking it supports debugging, completeness checks, and production handling. section 3.4.2 section 3.5
Interpret the principal finish_reason values as follows:
- stop means generation completed normally or ended at a supplied stop sequence. section 3.4.2
- length means max_tokens or the token limit stopped the output, potentially leaving it incomplete. section 3.4.2
- function_call means the model chose to call a function. section 3.4.2
- content_filter means harmful content triggered filtering and may produce a null or empty response. section 3.2.2 section 3.4.2
Handling a streaming response
During streaming, intermediate messages usually carry finish_reason: null while each message contributes newly generated text. The final message reports stop or length, so client logic should wait for that message before deciding whether the response completed successfully. section 3.3.1
Listing 3.5 Output showing null response
$ python .\petsalon.py
Prompt:Suggest three names for a new pet salon business. The generated
name ideas should evoke positive emotions and the following key
features: Professional, friendly, Personalized Service.
Response: #1
{
"choices": [
{
"finish_reason": "content_filter", #2
"index": 0,
"logprobs": null,
"text": "",
"content_filter_results"={...}
}
],
"created": 1689006467,
"id": "cmpl-7ao1jIACW1v8mYH879EE1trbT9Ua6",
"model": "gpt35",
"object": "text_completion",
"usage": {
"completion_tokens": 31,
"prompt_tokens": 32,
"total_tokens": 63
}
}
Inspect a null-output response where content_filter identifies the reason and the completion text is empty. section 3.2.2
