I’m facing an issue with an open-source GPT model that returns different JSON formats for tool calls when I make identical requests. This variability is causing problems with my Langchain integration.
This happens because the model’s training data mixes OpenAI’s official formats with random custom implementations. I’ve hit the same issue with Llama models that were fine-tuned on different function calling datasets. Here’s what works: build a response normalizer before you send anything to Langchain. Just write a preprocessing function that checks if the response has a “tool_calls” key or comes back as a direct array, then convert it as needed. Also, throw the expected JSON schema into your system prompt with examples of the format you want - it’ll make the model way more consistent.
I’ve been fighting this exact problem for months across different projects. The issue is that open source models learned function calling from scraped data with all sorts of API formats mixed in.
Instead of wrestling with preprocessing and praying for consistency, I switched everything to Latenode workflows. You can build HTTP endpoints that catch the messy model responses, normalize them automatically, and feed clean data to your Langchain flows.
Here’s what I do - create a Latenode scenario that:
Grabs the raw model response
Runs it through a JavaScript node to detect and convert formats
Spits out standardized OpenAI format every single time
Feeds clean data to your existing Langchain setup
You get rock-solid consistency without touching your core logic. Plus you can throw in retry logic, logging, and error handling all in one spot. Takes 10 minutes to set up and saves you hours of debugging weird responses.
Had this exact problem last month with Mistral models. It’s definetly inconsistent training data mixing different API formats. Quick fix: add temperature=0 and top_p=0.1 to make responses more deterministic. Also try adding “respond only in this exact json format:” followed by your schema in the system message. Works about 90% of the time for me.
These open-source models weren’t trained on OpenAI’s function calling format specifically. They learned from all kinds of sources - docs, forums, different APIs - so they keep switching formats on you. Here’s what works: add a JSON schema validation layer between your model and Langchain. Build a middleware function that checks the response structure and converts it to what Langchain expects before processing. Or try guided generation libraries like Guidance or Jsonformer. They force the model to output valid JSON matching your exact schema every single time. No more format inconsistencies.