-
Notifications
You must be signed in to change notification settings - Fork 323
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
Use guardrails for code validation #345
Comments
Hi, Thanks for the detailed issue. The additional tokens may be from the gr. json prompt key. That adds a decent amount of weight to the prompt, do you have a comparison in which that is not used? I think that would be good data to collect. Another thing you could do to reduce token count is to use string-style validation instead of pydantic/structured validation. You can apply the BugFreePythonCode validator to a guard structure like this - https://docs.guardrailsai.com/defining_guards/strings/. With a little bit of prompt engineering, I think you can slim down your token count considerably using this approach. Would love to see results/help with this longer term! Feel free to post here or work with us on discord! |
Hi, I appreciate your understanding regarding the token usage, as retries naturally lead to more tokens being used. However, I am particularly concerned about the quality of the output. As you can see from the attached image above, the simple code used to generate the Python code:
appears to perform better than the code using guardrails:
The accuracy achieved using the simple openai api is Thank you for your time and assistance. |
LLMs are better at generating code in a block than in a JSON field. Try using |
Thanks, I tried to use the following
And the validated_response response is not executable since it returns a string, underlying the an example response would be
|
Some more prompt engineering might help, like asking it in the prompt to only return a python code block without any surrounding text. |
Thanks, does guardrails naturally support it? |
This is the example we've got, though it generates the code as part of a JSON. https://docs.guardrailsai.com/examples/bug_free_python_code/#step-3-wrap-the-llm-api-call-with-guard Have you tried using the prompt in that example, generating a string instead of a JSON? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
This issue was closed because it has been stalled for 14 days with no activity. |
Hi,
I am the maintainer of YiVal https://github.com/YiVal/YiVal, currently we are trying to use guardrails to help us generate valid python code.
To get started, I do a quick evaluation, here is the code:
https://github.com/YiVal/YiVal/blob/master/demo/guardrails/run_leetcode.py
I download 80 leetcode questions and ask gpt-3.5-turo to generate python code for it, the pass / fail will basically be judged from if eval can run. I just follow the colab here:
https://github.com/ShreyaR/guardrails/blob/main/docs/examples/bug_free_python_code.ipynb
I use the same prompt without guardrail as comparison,
Here is the results
as you can see, with guardrils, the failed rate is higher and we use more token compared to just using GPT raw api
I am wondering if I there is anything wrong that I am doing here. This could also help others who might have the same issue
Thanks in advance for taking a look!
The text was updated successfully, but these errors were encountered: