Fixing Deserialization Failure for Enum with Empty String finish_reason
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 65/100
Research direction
Start at org.springframework.ai.openai.api.OpenAiApi$ChatCompletionFinishReason and reproduce the reported ChatCompletionChunk JSON with an empty finish_reason. Confirm that the enum deserializes both an empty string and null without the InvalidFormatException; the issue is done when the provided payload can be parsed normally.
Written by the indexing model from the issue text.
Description
Bug description
Deserialization of org.springframework.ai.openai.api.OpenAiApi$ChatCompletionFinishReason fails when the finish_reason field is an empty string "" rather than null during the step-by-step inference process. For instance, while the model is inferring step-by-step, the finish_reason field typically returns an empty string "" or null until all tokens are returned. Due to the following enum definition, "" cannot be directly handled:
public static enum ChatCompletionFinishReason {
@JsonProperty("stop")
STOP,
@JsonProperty("length")
LENGTH,
@JsonProperty("content_filter")
CONTENT_FILTER,
@JsonProperty("tool_calls")
TOOL_CALLS,
@JsonProperty("tool_call")
TOOL_CALL;
private ChatCompletionFinishReason() {
}
}
Environment
Please provide as many details as possible: Spring AI version, Java version, which vector store you use if any, etc
1.0.0-M6
Steps to reproduce
Steps to reproduce the issue.
Expected behavior
A clear and concise description of what you expected to happen.
when finish_reason is "",it can be deserialized normally
Minimal Complete Reproducible example
Please provide a failing test or a minimal complete verifiable example that reproduces the issue.
Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.
com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot coerce empty String ("") to org.springframework.ai.openai.api.OpenAiApi$ChatCompletionFinishReason value (but could if coercion was enabled using CoercionConfig)
at [Source: (String)"{"id":"xxxxxx","object":"chat.completion.chunk","created":1742218321,"model":"xxxx","choices":[{"index":0,"delta":{"role":"assistant","content":"","tool_calls":null,"reasoning_content":null},"logprobs":null,"finish_reason":"","matched_stop":null}],"usage":null}"; line: 1, column: 257] (through reference chain: org.springframework.ai.openai.api.OpenAiApi$ChatCompletionChunk["choices"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionChunk$ChunkChoice["finish_reason"])
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spring-projects/spring-ai
-
status: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
spring-projects/spring-ai#7022 · 2 comments ·
-
status: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
spring-projects/spring-ai#7000 ·
-
status: waiting-for-triage
Difficulty 1/5 Under an hour Newbie friendliness 90/100
spring-projects/spring-ai#6998 ·
-
[Bug - MCP server] @McpTool error messages are emitted twice when the thrown exception has no cause Openstatus: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
spring-projects/spring-ai#6948 · 1 comment · 1 reaction ·
-
status: waiting-for-triage
Difficulty 1/5 Under an hour Newbie friendliness 90/100
spring-projects/spring-ai#6940 · 1 comment ·
All issues in spring-projects/spring-ai
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100