Great question — answering as the UphillTech team:
You can set a minimum threshold and short-circuit if all retrieved docs are below it, but that should just be your first gate, not the only one. A better pattern in LangChain is to introduce an LLM-based grading step before you generate the final answer. After retrieving documents, send the user query plus the retrieved chunks to a small grading prompt. Ask the model to return structured output like “relevant: true/false” and maybe a confidence score. If the grader says the docs are not relevant enough, you either trigger your fallback (web search tool) or return a controlled “I don’t know” response. You can also add a second validation step after generation. Generate the answer strictly...
Full answer by Vultieris: https://stackoverflow.stackexchange.com/a/79900710 (CC BY-SA 4.0).
Need it done for your business? UphillTech.