Skip to content

fix: better error message for llm metadata extractor - #11477

Merged
sjrl merged 1 commit into
mainfrom
fix-llm-metadata-extractor-prompt-error
Jun 2, 2026
Merged

fix: better error message for llm metadata extractor#11477
sjrl merged 1 commit into
mainfrom
fix-llm-metadata-extractor-prompt-error

Conversation

@sjrl

@sjrl sjrl commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Related Issues

  • fixes issue that @ju-gu ran into in our platform

Proposed Changes:

Fixes the error message raised by the LLMMetadataExtractor. Previously it would raise an IndexError when trying to raise the ValueError since we assumed the number of variables in the prompt would be non-zero.

How did you test it?

Added new unit tests.

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@sjrl
sjrl requested a review from a team as a code owner June 2, 2026 09:20
@sjrl
sjrl requested review from davidsbatista and removed request for a team June 2, 2026 09:20
@sjrl sjrl self-assigned this Jun 2, 2026
@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
haystack-docs Ready Ready Preview, Comment Jun 2, 2026 9:21am

Request Review

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/extractors
  llm_metadata_extractor.py
Project Total  

This report was generated by python-coverage-comment-action

@claude

claude Bot commented Jun 2, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@davidsbatista davidsbatista left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good.

I can't see where the IndexError was removed; through the diff, it's still a ValueError as before, only the test condition and the message changed.

ast = SandboxedEnvironment().parse(prompt)
template_variables = meta.find_undeclared_variables(ast)
variables = list(template_variables)
if len(variables) > 1 or variables[0] != "document":

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this line caused the index error variables[0] since it assumes variables has at least one item in it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah got it now! 👍🏽 thanks

@sjrl
sjrl merged commit 85e183f into main Jun 2, 2026
30 checks passed
@sjrl
sjrl deleted the fix-llm-metadata-extractor-prompt-error branch June 2, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants