Skip to content

Use json-repair package to fix LLM generated json#226

Merged
willtai merged 8 commits intoneo4j:mainfrom
willtai:improve-llm-generated-json-fixing
Dec 10, 2024
Merged

Use json-repair package to fix LLM generated json#226
willtai merged 8 commits intoneo4j:mainfrom
willtai:improve-llm-generated-json-fixing

Conversation

@willtai
Copy link
Contributor

@willtai willtai commented Dec 6, 2024

Description

This PR improves on fixing LLM-generated JSON objects for the EntityRelationExtractor with the following:

  • Usage of the json-repair package to fix LLM generated JSON objects.
  • Additional instructions to the LLM prompt.

The previous function to clean up LLM generated JSON objects is now removed.

This was tested using several LLMs using Ollama. During testing, the prompt and model temperature were changed to encourage the LLM to generate invalid JSON. These outputs were used to validate the new methods.

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update
  • Project configuration change

Complexity

Complexity: Low

How Has This Been Tested?

  • Unit tests
  • E2E tests
  • Manual tests

Checklist

The following requirements should have been met (depending on the changes in the branch):

  • Documentation has been updated
  • Unit tests have been updated
  • E2E tests have been updated
  • Examples have been updated
  • New files have copyright header
  • CLA (https://neo4j.com/developer/cla/) has been signed
  • CHANGELOG.md updated if appropriate

@willtai willtai requested a review from a team as a code owner December 6, 2024 16:01
@willtai willtai force-pushed the improve-llm-generated-json-fixing branch from 2ddf3ed to dc1101d Compare December 6, 2024 16:20
@willtai willtai force-pushed the improve-llm-generated-json-fixing branch 2 times, most recently from c1ef1d6 to fadde05 Compare December 9, 2024 14:16
@willtai willtai force-pushed the improve-llm-generated-json-fixing branch from bf68808 to 20572c8 Compare December 9, 2024 16:40
@willtai willtai force-pushed the improve-llm-generated-json-fixing branch from 63e26cc to 84ac45a Compare December 9, 2024 16:46
@willtai willtai force-pushed the improve-llm-generated-json-fixing branch from 639cae2 to 0a629af Compare December 10, 2024 11:01
Copy link
Contributor

@stellasia stellasia left a comment

Choose a reason for hiding this comment

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

Minor comments, but looks good! Thanks for adding this @willtai , I think it will really improve user experience!

@willtai willtai force-pushed the improve-llm-generated-json-fixing branch from 0a629af to 801c3d9 Compare December 10, 2024 17:06
@willtai
Copy link
Contributor Author

willtai commented Dec 10, 2024

@CodiumAI-Agent /update_changelog

@QodoAI-Agent
Copy link

Changelog updates: 🔄

2024-12-10

Added

  • Integrated json-repair package to handle and repair invalid JSON generated by LLMs.
  • Introduced InvalidJSONError exception for handling cases where JSON repair fails.

Changed

  • Updated LLM prompts to include stricter instructions for generating valid JSON.
  • Improved JSON handling logic in the EntityRelationExtractor component.

to commit the new content to the CHANGELOG.md file, please type:
'/update_changelog --pr_update_changelog.push_changelog_changes=true'

@willtai willtai force-pushed the improve-llm-generated-json-fixing branch from ac75669 to 9a0a3f3 Compare December 10, 2024 18:02
@willtai willtai merged commit 0ac06b7 into neo4j:main Dec 10, 2024
@QodoAI-Agent
Copy link

Changelog updates: 🔄

2024-12-10

Added

  • Integrated json-repair package to handle and repair invalid JSON generated by LLMs.
  • Introduced InvalidJSONError exception for cases where JSON repair fails.

Changed

  • Enhanced LLM prompts with stricter instructions to ensure valid JSON generation.

to commit the new content to the CHANGELOG.md file, please type:
'/update_changelog --pr_update_changelog.push_changelog_changes=true'

@stellasia stellasia mentioned this pull request Dec 11, 2024
15 tasks
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.

4 participants