spring-projects / spring-projects/spring-ai

Enhance BeanOutputConverter to trim Preamble

Open
#4,336 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 10h
Merged PRs (30d)
5

Description

Every so often I'll get responses from LLMs that look like this:

I'll analyze and evaluate that for you. Here are the results
{
   "result" : "PASS"
}

Which results in BeanOutputConverter failing to parse the response.
o.s.ai.converter.BeanOutputConverter : Could not parse the given text to the desired target type:

Would it make sense to enhance BeanOutputConverters trimming logic to trim everything before the JSON payload?

Expected Behavior

When mapping a response from a ChatClient, if the response from the LLM contains a preamble before a valid JSON response, BeanOutputConverter should trim it and successfully parse the response.

Current Behavior

BeanOutputConverter fails to parse the response and throws and error.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at BeanOutputConverter and reproduce the issue with the sample response containing a preamble before the JSON payload. Confirm the converter can parse a valid JSON response with leading text, while preserving existing parsing behavior; the issue does not name a test file or other entry point.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
ai, backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.