Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Structured Output Parser Node): Refactor Output Parsers and Improve Error Handling #11148

Conversation

OlegIvaniv
Copy link
Contributor

@OlegIvaniv OlegIvaniv commented Oct 7, 2024

Summary

This PR refactors our output parser implementation, extracting them into individual classes and improving error handling, particularly for structured output parsers. These changes should improve our ability to provide user-friendly error messages while maintaining the functionality of the auto-fixing parser.

  • The N8nStructuredOutputParser now includes a context property to handle execution context and supports custom error mapping.
  • N8nOutputFixingParser integrates with the structured parser to attempt fixing invalid outputs.
  • N8nItemListOutputParser retains its functionality but is now part of the new parser structure.
  • Updated getOptionalOutputParsers utility to work with the new parser types.

Changes

  1. Extracted output parsers into separate classes:

    • N8nStructuredOutputParser
    • N8nOutputFixingParser
    • N8nItemListOutputParser
  2. Implemented error mapping in N8nStructuredOutputParser to allow for both user-friendly error messages and proper error handling in the auto-fixing parser.

  3. Removed proxy wrapping from logWrapper and instead manually populate input/output data from each parser class.

  4. Updated relevant nodes and utility functions to use the new parser classes.

  5. Adjusted test files to reflect the new structure and functionality and added tests for N8nOutputFixingParser and N8nItemListOutputParser nodes.

Related Linear tickets, Github issues, and Community forum posts

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system labels Oct 7, 2024
@OlegIvaniv OlegIvaniv changed the title refactor(Structured Output Parser Node): Refactor Output Parsers and Improve Error Handling feat(Structured Output Parser Node): Refactor Output Parsers and Improve Error Handling Oct 8, 2024
Copy link
Contributor

@burivuhster burivuhster left a comment

Choose a reason for hiding this comment

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

Awesome job! And kudos for writing tests.
I have only one comment about auto-fixing parser test case, could you please check?

burivuhster
burivuhster previously approved these changes Oct 22, 2024
Copy link

cypress bot commented Oct 22, 2024

n8n    Run #7478

Run Properties:  status check passed Passed #7478  •  git commit 0d6d5d190f: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 OlegIvaniv 🗃️ e2e/*
Project n8n
Branch Review ai-362-output-parser-errors-appear-on-chain-and-not-on-sub-node
Run status status check passed Passed #7478
Run duration 04m 17s
Commit git commit 0d6d5d190f: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 OlegIvaniv 🗃️ e2e/*
Committer Oleg Ivaniv
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 2
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 458
View all changes introduced in this branch ↗︎

Copy link
Contributor

✅ All Cypress E2E specs passed

Copy link
Contributor

✅ All Cypress E2E specs passed

@OlegIvaniv OlegIvaniv merged commit 45274f2 into master Oct 22, 2024
34 checks passed
@OlegIvaniv OlegIvaniv deleted the ai-362-output-parser-errors-appear-on-chain-and-not-on-sub-node branch October 22, 2024 08:47
@github-actions github-actions bot mentioned this pull request Oct 24, 2024
@janober
Copy link
Member

janober commented Oct 24, 2024

Got released with [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team Released ui Enhancement in /editor-ui or /design-system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants