Skip to content

fix: keep conversation notes when the model leaves quotes unescaped - #21139

Merged
Git-on-my-level merged 3 commits into
mainfrom
fix/errfix-1010-gcp-json-py-91-langchain-core-exceptions
Oct 13, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
fix/errfix-1010-gcp-json-py-91-langchain-core-exceptions

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

What changed and why

Conversation notes failed closed when the structure model left prose quotes unescaped inside an otherwise complete JSON object. JsonOutputParser raised OutputParserException from langchain_core/output_parsers/json.py:91, and _get_structured turned that into a processing failure, so the conversation never got a summary.

Error group (source: gcp):
{"source": "gcp", "service": "backend", "group": "json.py:91 | langchain_core.exceptions.OutputParserException: Invalid json output: {"title": "Fish identification", "overvi", "count": 1, "id": "gcp:backend-json-py-91-langchain-core-exceptions-outputparserexception-invalid-json-output-title-fish-identificati"}

Root cause

The traceback is process_conversation.py _get_structured → conversation_processing.py _get_shaped_conversation_notes → extraction_parser.parse. The completion is a StructuredExtraction object (title, overview, sections, …) whose string values contain raw " characters. Langchain's partial JSON repair cannot recover that shape (Expecting ',' delimiter immediately after the interior quote), so the strict parser raises and the notes call fails.

Fix

_parse_notes_model_output still parses with PydanticOutputParser. Only after that raises does it escape interior quotes whose next non-space character is not a JSON closer (, } ] : "), then parse again. Valid JSON, already-escaped quotes, and a missing comma between fields are unchanged.

Product invariants affected

none

How it was verified

python3 -m py_compile backend/utils/llm/conversation_processing.py backend/tests/unit/test_conversation_notes_json_quotes.py
# COMPILE_OK

backend/.venv python -m pytest tests/unit/test_conversation_notes_json_quotes.py -q --tb=short
# ....  [100%]
# 4 passed in 3.72s

The logged Fish identification completion still raises on the strict parser and now parses through _parse_notes_model_output as StructuredExtraction with that title, a non-empty overview, and one section.

Tests

backend/tests/unit/test_conversation_notes_json_quotes.py covers unescaped quotes in overview and in a section body, already-escaped quotes, and a missing comma that must still raise.

UI evidence

UI-Evidence: none -- backend notes parser only

Failure class (fixes)

Failure-Class: none

View guided diff Turn on auto-fix

JsonOutputParser drops the whole summary when a notes completion quotes a phrase inside a JSON string.

Co-authored-by: Cursor <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T15:06:39.069579Z 1e10235 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c480f88de8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +337 to +341
if follower >= length or text[follower] in _JSON_STRING_CLOSER_FOLLOWERS:
out.append(char)
in_string = False
else:
out.append('\\"')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Escape prose quotes followed by JSON-like punctuation

When an unescaped quoted phrase is followed by a comma, colon, bracket, or the end of the field—for example, "overview":"He said "hi", then left"—this condition mistakes the interior closing quote for the JSON string boundary. The repair consequently produces malformed JSON such as "He said \"hi", then left", so the retry can still fail or the partial JSON parser can silently return a truncated overview. Quoted phrases ending a sentence or preceding punctuation are common model output, so this still loses or corrupts conversation notes in the scenario the change is intended to recover.

Useful? React with 👍 / 👎.

Comment on lines +356 to +357
except OutputParserException:
repaired = _escape_interior_json_quotes(text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Record successful quote-repair fallbacks

Whenever the initial parse fails but the repair succeeds, this new fail-open branch changes correctness without calling utils.observability.fallback.record_fallback. That makes recovered malformed model responses invisible to fallback telemetry, preventing operators from measuring recurrence or detecting when the repair path starts masking a provider regression.

AGENTS.md reference: backend/AGENTS.md:L312-L312

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb25d1426c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +349 to +350
if char == '"':
in_string = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit quote scanning to the JSON payload

When the model wraps the malformed object in a fenced response with a quoted preamble, such as Here is the "requested" JSON:, this branch treats the preamble's first quote as the start of a JSON string. It then escapes structural quotes inside the fenced object (for example, turning its opening key into \{"title...), so the retry still raises and the conversation loses its notes even though PydanticOutputParser normally accepts fenced JSON. Extract the fenced/object payload before applying this repair, or otherwise avoid tracking quotes in surrounding prose.

Useful? React with 👍 / 👎.

Unit tests replace langchain_core with a non-package stub, so a module-level exceptions import prevents conversation routers from loading.

Co-authored-by: Cursor <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

errfix finisher: this PR has been open >3 days without merging — escalating to a human.

@Git-on-my-level
Git-on-my-level merged commit f899bca into main Oct 13, 2026
56 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/errfix-1010-gcp-json-py-91-langchain-core-exceptions branch October 13, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant