Skip to content

Conversation

@dmontagu
Copy link
Contributor

Improves the rendering of the tool output when shown as markdown. Costs ~2.5% more input tokens when it's relevant, but considering this should NOT be happening frequently (if it is, you want to be tweaking your implementation to avoid retries anyway), I think the readability improvement during debugging is worth the small increase in token usage.

Before:
image

After:
image

@dmontagu dmontagu requested a review from DouweM October 17, 2025 18:57
@github-actions
Copy link

github-actions bot commented Oct 17, 2025

Docs Preview

commit: d893b87
Preview URL: https://e524ae13-pydantic-ai-previews.pydantic.workers.dev

@samuelcolvin
Copy link
Member

fine by me, should we use format_as_xml anyway?

description = f'{len(self.content)} validation errors: {json_errors.decode()}'
plural = isinstance(self.content, list) and len(self.content) != 1
description = (
f'{len(self.content)} validation error{"s" if plural else ""}:\n```json\n{json_errors.decode()}\n```'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like using format_as_xml as Samuel suggested

@dmontagu
Copy link
Contributor Author

dmontagu commented Oct 24, 2025

I'd suggest we do that in a separate PR, I worry it will add a lot of tokens and hence be more debatable of an "improvement", I think this change is a bit of a no-brainer and doesn't preclude us changing to xml in the near future

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.

3 participants