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] XMLSyntaxError #170

Closed
jy-tan opened this issue May 30, 2023 · 2 comments · Fixed by #196
Closed

[bug] XMLSyntaxError #170

jy-tan opened this issue May 30, 2023 · 2 comments · Fixed by #196
Labels
bug Something isn't working

Comments

@jy-tan
Copy link

jy-tan commented May 30, 2023

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.

@jy-tan jy-tan added the bug Something isn't working label May 30, 2023
@maxdml
Copy link

maxdml commented Jun 5, 2023

Can you share what is the content of line 5 of your input document?

If there is a double quote in there, can you replace it with &quot; and re-run?

@irgolic
Copy link
Contributor

irgolic commented Jun 26, 2023

Hey @jy-tan, @maxdml, sorry for the late reply. I've pushed a PR that automatically replaces " with &quot;, could you give it a try?

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

Successfully merging a pull request may close this issue.

3 participants