Skip to content

fix: convert dict entities to text strings for highlights field (Fixes #386)#667

Open
lb1192176991-lab wants to merge 1 commit into
ritesh-1918:gssocfrom
lb1192176991-lab:fix/highlights-entityinfo-500-386
Open

fix: convert dict entities to text strings for highlights field (Fixes #386)#667
lb1192176991-lab wants to merge 1 commit into
ritesh-1918:gssocfrom
lb1192176991-lab:fix/highlights-entityinfo-500-386

Conversation

@lb1192176991-lab
Copy link
Copy Markdown

What

The /ai/analyze endpoint crashes with a 500 error because the highlights field in TicketResponse is typed as list[str] but receives list[dict] objects.

Root cause: ner_service.extract_entities() returns list[dict] with keys {"text", "label", "confidence"}. When this list is passed to highlights=[e.text for e in entities], it crashes with AttributeError: dict object has no attribute text because the entities variable is still list[dict] at that point in the code (it is only converted to list[EntityInfo] in the separate entities= parameter).

Fix: Changed line 1855 from:

highlights=[e.text for e in entities] if entities else []

to:

highlights=[e.get("text", "") for e in entities] if entities else []

The analyze_stream() endpoint already had the correct form (e.get("text", "")) on line 2019 — it was only the analyze_only() function that had the wrong access pattern.

Why

Users hitting the /ai/analyze endpoint get a 500 error when NER entities are present, making the AI analysis feature completely broken whenever entities are detected. Pydantic v2 cannot coerce dict objects into str.

Testing

  • When entities = [{"text": "Python", "label": "tech", "confidence": 0.95}], highlights becomes ["Python"]
  • When entities = [], highlights becomes []
  • When entities = [{"label": "tech"}] (missing text key), highlights becomes [""] ✓ (graceful fallback)

…ritesh-1918#386)

entities from ner_service.extract_entities() returns list[dict] with
keys {"text", "label", "confidence"}, not EntityInfo objects. The
highlights field expects list[str].

Changed highlights=[e.text for e in entities] to
highlights=[e.get("text", "") for e in entities] to properly extract
text from dict entries.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@lb1192176991-lab is attempting to deploy a commit to the ritesh Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cedd1373-7888-4bfb-a5f3-8acfd4a6739c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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