Skip to content

Friendly error messages, clean research text, and remove eval of model output - #2

Merged
dpelezo merged 5 commits into
masterfrom
fix/friendly-errors
Nov 23, 2026
Merged

dpelezo merged 5 commits into
masterfrom
fix/friendly-errors

Conversation

@dpelezo

@dpelezo dpelezo commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Summary

Visitors see short, friendly notices instead of raw provider errors, and deep research no longer shows broken text. This also fixes an eval() of model output.

Changes

  • Friendly errors (app/services/errors.py):
    • No API credit, a bad key or a retired model shows "The assistant is temporarily unavailable. Please try again later."
    • Rate limits and outages show "The assistant is busy right now. Please try again in a minute."
    • Anything else shows a generic retry message.
    • The full exception still goes to the logs.
  • API, additive only: chat messages gain is_error, and /api/research/status/{id} gains error. Error notices are no longer replayed to the model as conversation history.
  • Clean search text: retrieve_web_content used to render Exa highlights as a Python list, and the research parser cut that text at every quote mark. That produced the escaped \n and the sentences cut off at apostrophes. The tool now returns plain-text sources with URLs.
  • Research fallback: when Claude cannot write the report (for example, no credit), the result lists the sources found as Markdown links with short excerpts, instead of "Finding 1… Finding 10" fragments. The report prompt now asks for Markdown with cited links.
  • Security: search query lists from the model were parsed with eval(). The model reads web content, so a malicious page could inject code. Now ast.literal_eval.

Verification

  • ruff check app tests: passes
  • pytest -q on Python 3.11: 31 passed (19 new), including an end-to-end research run with a failing model and a fake search tool
  • Not verified against the live Anthropic and Exa APIs

Frontend

The matching frontend PR reads is_error and the research error, and renders Markdown. Merge this one first. The frontend still works with the old API, but this one changes the text it will show.


Generated by Claude Code

dpelezo and others added 4 commits November 23, 2026 12:32
No API credit, a bad key or a retired model now shows 'The assistant is
temporarily unavailable'; rate limits and outages ask the user to retry.
Chat replies carry is_error, research status carries error, and error
notices are not sent back to the model as history.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XtW6Y5JF5GNt1txL7PriFg
The search tool rendered highlights as a Python list, and the parser split
that text at every quote mark, so reports showed escaped newlines and
sentences cut off at apostrophes. Sources are now plain text with their
URLs, and when the model cannot write the report the result lists the
sources with short excerpts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XtW6Y5JF5GNt1txL7PriFg
Search query lists returned by the model were run through eval(). The
model reads text from web pages, so a page could inject code that would
run on the server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XtW6Y5JF5GNt1txL7PriFg
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
ai-assistant-api Ready Ready Preview Nov 23, 2026 6:40pm UTC

@dpelezo
dpelezo merged commit fd695d1 into master Nov 23, 2026
4 checks passed
@dpelezo
dpelezo deleted the fix/friendly-errors branch November 23, 2026 21:45

This branch was successfully deployed

1 active deployment
Preview — 4ac1124c Deployed Nov 23, 2026 by vercel[bot]
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