Skip to content

[bug] XMLSyntaxError #170

Closed
Closed
@jy-tan

Description

@jy-tan

Describe the bug
I encountered XMLSyntaxError when trying to reproduce the text summarization example.

To Reproduce
Steps to reproduce the behavior:

Rail spec:

<rail version="0.1">

<script language='python'>
document = open("search.txt", "r").read()
</script>

<output>
    <string
        name="summary"
        description="Summarize the given document faithfully."
        format="similar-to-document: {document}, 0.60"
        on-fail-similar-to-document="filter" 
    />
</output>

<prompt>
Summarize the following document:

{{document}}

@complete_json_suffix
</prompt>
</rail>

(I only changed the document path, which is a valid path for me.)

Running the command

guard = gd.Guard.from_rail_string(rail_str)

gives the following error:

Traceback (most recent call last):

  File /databricks/python/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3378 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File <command-3862015891448427>:27
    guard = gd.Guard.from_rail_string(rail_str)

  File /local_disk0/.ephemeral_nfs/envs/pythonEnv-84b67d00-0c2e-469a-8873-18f5bc500df3/lib/python3.9/site-packages/guardrails/guard.py:132 in from_rail_string
    return cls(Rail.from_string(rail_string), num_reasks=num_reasks)

  File /local_disk0/.ephemeral_nfs/envs/pythonEnv-84b67d00-0c2e-469a-8873-18f5bc500df3/lib/python3.9/site-packages/guardrails/rail.py:108 in from_string
    return cls.from_xml(ET.fromstring(string, parser=XMLPARSER))

  File /local_disk0/.ephemeral_nfs/envs/pythonEnv-84b67d00-0c2e-469a-8873-18f5bc500df3/lib/python3.9/site-packages/guardrails/rail.py:139 in from_xml
    raw_output_schema = ET.fromstring(raw_output_schema, parser=XMLPARSER)

  File src/lxml/etree.pyx:3257 in lxml.etree.fromstring

  File src/lxml/parser.pxi:1916 in lxml.etree._parseMemoryDocument

  File src/lxml/parser.pxi:1796 in lxml.etree._parseDoc

  File src/lxml/parser.pxi:1085 in lxml.etree._BaseParser._parseUnicodeDoc

  File src/lxml/parser.pxi:618 in lxml.etree._ParserContext._handleParseResultDoc

  File src/lxml/parser.pxi:728 in lxml.etree._handleParseResult

  File src/lxml/parser.pxi:657 in lxml.etree._raiseParseError

  File <string>:6
XMLSyntaxError: attributes construct error, line 6, column 196

Expected behavior
The Guard should be created with no errors.

Library version:
Installed directly from GitHub, main branch.

Additional context
Removing the

format="similar-to-document: {document}, 0.60"
on-fail-similar-to-document="filter" 

doesn't throw an error, but that would defeat its intended purpose.

FWIW, switching to the saliency-check validator throws the same error.

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