Skip to content

[bug] Type annotated objects in pydantic guards incorrectly transpile to XML #319

@irgolic

Description

@irgolic

Describe the bug
When making a guard from a pydantic model, if a Dict has type arguments on it, it transpiles into XML in a way that doesn't work.

Relevant Discord thread:
https://discord.com/channels/1085077079697150023/1149032565844475965/1149296871517470810

To Reproduce

from pydantic import BaseModel
from guardrails import Guard

class CorrectAnswers(BaseModel):
    all_of: Dict[str, str] = {}
    any_of_groups: List[Dict[str, str]] = []
    not_all_of_groups: List[Dict[str, str]] = []
    not_any_of: Dict[str, str] = {}

Guard.from_pydantic(CorrectAnswers)

Expected behavior
XML guards don't support specifying types in objects with arbitrary elements, so it should probably just act like this:

class CorrectAnswers(BaseModel):
    all_of: Dict = {}
    any_of_groups: List[Dict] = []
    not_all_of_groups: List[Dict] = []
    not_any_of: Dict = {}

Library version:
0.2.0

Additional context
This bug will probably be fixed when we migrate to XML-invariant internals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions