-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypedChainOfThought throw ValueError: 'Too many retries trying to get the correct output format. Try simplifying the requirements.' #957
Comments
I've been able to reproduce your problem and it seems the results are highly dependent on the model
dolphin-mixtral:8x7b-v2.6 works extremely well from the first go.
|
I think making the model return correct schemas should be a part of optimizers processes. I'll try to make an example in a few days. |
I'm wondering if there is a way to optimize the output schema only, so I won't need provide any training data for it. |
It seams that DSPy only outputs JSON as plain text, even the model supports JSON schema. This is quite problematic, even the simple example from the documentation can't generate JSON properly on first try. History of the Typed Predictors example from the documentation using GPT-4:
{"answer": "the lazy dog", "confidence": 1.0} |
Why rely on model performance for adhering to structured output instead of constrained generation? Why not integrate with Outlines or SGLang? |
+1 happens for normal usecases even using gpt4o. so definitely optimisations are needed. |
I don't know if this can be useful to anyone, but here is how I proceeded to solve this problem. First, I noticed that the outputs of LLMs are often truncated, so I systematically increased the value of max_tokens (I set it to 2048, which is sufficient for most of my use cases). def extract_valid_json(self, input_string):
Then I added the following lines in the first 'try' block of the forward method, right after 'value = completion[name]': valid_json_object, remaining = self.extract_valid_json(value) Claude |
In some cases the
TypedChainOfThought
would throw the following error, butTypedPredictor
would work fine.Reproducible example:
Error:
Using
TypedPredictor
:Result:
The text was updated successfully, but these errors were encountered: