DEV Community

izharhaq1987
izharhaq1987

Posted on

Testing FastAPI and LangChain with Two Response Modes

I wanted to share a small detail from the customer-support workflow I built last week with FastAPI and LangChain. It’s something that kept the project easy to test and saved time later.

I set up the app so each request can run in two modes:

I. Mock mode
II. Real LLM mode

Mock mode returns fixed responses for each intent. It gave me a stable baseline during debugging, since nothing depended on an external LLM call. Real mode uses OpenAI and follows the same structure, so switching back and forth didn’t break anything.

One thing that worked well was keeping both paths inside the same handler. The logic stays in one place, and it’s obvious how the request flows. It’s a simple pattern, but it helps when you’re checking user messages, routing intents, and comparing outputs during refinement.

If anyone’s building something similar, having these two modes early on makes the pipeline easier to reason about.

Top comments (0)