Common error scenarios
Handle LLM provider errors
When the LLM provider is unavailable or returns an error, the chat completions endpoint forwards the error. Wrap your requests in error handling to provide a fallback:Fall back to regular search
When conversational search fails, you can fall back to a standard keyword or hybrid search. This ensures users still get results:Handle empty search results
When the LLM cannot find relevant documents, it may hallucinate an answer or give a vague response. Use guardrails in your system prompt to handle this:_meiliSearchSources tool call. If the sources array is empty, display a helpful message:
Handle rate limiting
LLM providers enforce rate limits based on requests per minute or tokens per minute. When you hit these limits, implement backoff:- Use a higher-tier API key with your LLM provider
- Implement client-side debouncing to avoid sending requests on every keystroke
- Cache responses for repeated questions
Manage context window limits
Long conversations can exceed the LLM’s context window. When this happens, the provider returns an error. Trim older messages from the conversation history to stay within limits:Display errors in your UI
When an error occurs, give users clear feedback and actionable next steps. Avoid exposing raw error messages or stack traces:Next steps
Configure guardrails
Reduce hallucination with system prompts
Stream chat responses
Implement real-time streaming for chat responses