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

Fix how quotes are parsed in json #2189

Merged
merged 10 commits into from
Feb 21, 2025
Merged

Fix how quotes are parsed in json #2189

merged 10 commits into from
Feb 21, 2025

Conversation

dirkbrnd
Copy link
Contributor

Description

When we have agents that respond with JSON with quotes in the fields, then it breaks parsing. This fixes that.

Fixes #2128


Type of change

Please check the options that are relevant:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Model update (Addition or modification of models)
  • Other (please describe):

Checklist

  • Adherence to standards: Code complies with Agno’s style guidelines and best practices.
  • Formatting and validation: You have run ./scripts/format.sh and ./scripts/validate.sh to ensure code is formatted and linted.
  • Self-review completed: A thorough review has been performed by the contributor(s).
  • Documentation: Docstrings and comments have been added or updated for any complex logic.
  • Examples and guides: Relevant cookbook examples have been included or updated (if applicable).
  • Tested in a clean environment: Changes have been tested in a clean environment to confirm expected behavior.
  • Tests (optional): Tests have been added or updated to cover any new or changed functionality.

Additional Notes

Include any deployment notes, performance implications, security considerations, or other relevant information (e.g., screenshots or logs if applicable).

@dirkbrnd dirkbrnd requested a review from a team as a code owner February 19, 2025 15:27
@manthanguptaa
Copy link
Contributor

manthanguptaa commented Feb 21, 2025

I tried running this example you mentioned in the issue

from typing import List

from agno.agent import Agent, RunResponse  # noqa
from agno.models.anthropic import Claude
from pydantic import BaseModel, Field
from rich.pretty import pprint  # noqa


class MovieScript(BaseModel):
    script: str = Field(
        ..., description="The script of the movie."
    )


movie_agent = Agent(
    model=Claude(id="claude-3-5-sonnet-20240620"),
    description="You help people write movie scripts. Always add some example dialog in your scripts in double quotes.",
    response_model=MovieScript,
    structured_outputs=True,
)

# Get the response in a variable
run: RunResponse = movie_agent.run("New York")
pprint(run.content)

After running it thrice it failed to convert it to json all 3 times.
Screenshot 2025-02-21 at 9 21 51 AM

@dirkbrnd dirkbrnd merged commit a2070cb into main Feb 21, 2025
1 check passed
@dirkbrnd dirkbrnd deleted the fix-invalid-json-responses branch February 21, 2025 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid JSON response when using Claude due to unescaped quotes
3 participants