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

fix(Auto-fixing Output Parser Node): Only run retry chain on parsing errors #11569

Merged
merged 5 commits into from
Nov 6, 2024

Conversation

OlegIvaniv
Copy link
Contributor

Summary

This PR fixes two issues with the OutputParserAutofixing node:

  1. The node uses a hardcoded prompt template which fails to handle complex output formats effectively
  2. The error handling mechanism attempts to fix all errors indiscriminately, including non-parsing related errors (like network issues)

Changes

  • Improved error handling by only retrying on OutputParserException
  • Added option to customize the fix prompt template used in OutputParserAutofixing
  • Added validation for fix prompt template (must contain {error} placeholder)
  • Updated unit tests to cover new functionality and edge cases

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 the n8n team Authored by the n8n team label Nov 5, 2024
jeanpaul
jeanpaul previously approved these changes Nov 6, 2024

const parser = new N8nOutputFixingParser(this, model, outputParser);
if (prompt.length === 0 || !prompt.includes('{error}')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the other placeholders (instructions, completion) not required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure how much we should restrict this; perhaps users would use it with fully custom prompts that provided the completion from other parts of the workflow. But of course, with the default prompt, providing the other two placeholders is semi-required, so it'll work more reliably.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it doesn't error, apparently, but it does not yield good results, it looks like (removed the "instructions" bit, but that left an empty object, instead of something that actually matches the output parser...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should add these placeholders as a hint underneath the prompt-window?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Did that + added more descriptive description
CleanShot 2024-11-06 at 12 10 09

@jeanpaul
Copy link
Contributor

jeanpaul commented Nov 6, 2024

The only thing I wasn't sure about was the name "Fix Prompt" -- is this clear enough for the user?

@OlegIvaniv
Copy link
Contributor Author

The only thing I wasn't sure about was the name "Fix Prompt" -- is this clear enough for the user?

Got any ideas for a better name? Perhaps Retry Prompt?

@jeanpaul
Copy link
Contributor

jeanpaul commented Nov 6, 2024

The only thing I wasn't sure about was the name "Fix Prompt" -- is this clear enough for the user?

Got any ideas for a better name? Perhaps Retry Prompt?

Yep, that sounds good. Probably better to not have too long a name, otherwise, I'd try to be a bit more descriptive like "Prompt for fixing the output".
Maybe that should go into the description?

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 57.14286% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...in/nodes/agents/Agent/agents/ToolsAgent/execute.ts 0.00% 8 Missing ⚠️
...hain/utils/output_parsers/N8nOutputFixingParser.ts 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

cypress bot commented Nov 6, 2024

n8n    Run #7748

Run Properties:  status check passed Passed #7748  •  git commit 4f85327eb0: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 OlegIvaniv 🗃️ e2e/*
Project n8n
Branch Review ai-437-bug-auto-fixing-parser-goes-wild
Run status status check passed Passed #7748
Run duration 04m 39s
Commit git commit 4f85327eb0: 🌳 🖥️ 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 2
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 460
View all changes introduced in this branch ↗︎

Copy link
Contributor

github-actions bot commented Nov 6, 2024

✅ All Cypress E2E specs passed

@OlegIvaniv OlegIvaniv merged commit 21b31e4 into master Nov 6, 2024
36 checks passed
@OlegIvaniv OlegIvaniv deleted the ai-437-bug-auto-fixing-parser-goes-wild branch November 6, 2024 16:24
@github-actions github-actions bot mentioned this pull request Nov 13, 2024
@janober
Copy link
Member

janober commented Nov 13, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants