Skip to content
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

[bug] JSON validation converts null values to True:bool #641

Closed
1-Archit-1 opened this issue Mar 14, 2024 · 1 comment
Closed

[bug] JSON validation converts null values to True:bool #641

1-Archit-1 opened this issue Mar 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@1-Archit-1
Copy link

1-Archit-1 commented Mar 14, 2024

Describe the Bug
On validation using guard null values returned by the llm for specified fields is converted to True.

To Reproduce

import openai
from guardrails import Guard
from pydantic import BaseModel, Field
from typing import Optional

class Car(BaseModel):
    name: str = Field(description="name of the car")
    color: Optional[str] = Field(description="This field is nullable")

guard = Guard.from_pydantic(output_class=Car)

raw_llm_output, validated_output, *others =  response = guard(
    llm_api=openai.chat.completions.create,
    prompt="""Generate a car object. Only add fields described below. Do not add any new fields
    ${gr.complete_json_suffix}"""
)

print(validated_output)

Expected behavior
The validated output should be {'car': 'Honda, 'color':None}
Instead we get {'car': 'Honda, 'color':True}

Library version:
Version (e.g. 0.4.0)

@1-Archit-1 1-Archit-1 added the bug Something isn't working label Mar 14, 2024
@CalebCourier
Copy link
Collaborator

Fixed in 0.4.1

See #604
and #479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants