Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/runner/templates/agents/python/pydantic-ai/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,26 @@ def {{ tool.name }}(context: RunContext, {% for param in tool.parameters.require
{% endif %}
{% endfor %}

try:
{% if user_content is string %}
result = await agent.run("{{ user_content }}")
result = await agent.run("{{ user_content }}")
{% else %}
# Multimodal content - build message parts
message_parts = []
# Multimodal content - build message parts
message_parts = []
{% for part in user_content %}
{% if part.type == 'text' %}
message_parts.append("{{ part.text }}")
message_parts.append("{{ part.text }}")
{% elif part.type == 'image' %}
message_parts.append(ImageUrl(url="data:{{ part.mediaType }};base64,{{ part.base64 }}"))
message_parts.append(ImageUrl(url="data:{{ part.mediaType }};base64,{{ part.base64 }}"))
{% endif %}
{% endfor %}
result = await agent.run(message_parts)
result = await agent.run(message_parts)
{% endif %}

# Print response
print(f"Turn {{ loop.index }} Response: {result.output}")
# Print response
print(f"Turn {{ loop.index }} Response: {result.output}")
except Exception as e:
print(f"Turn {{ loop.index }} Error: {type(e).__name__}: {e}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Swallowed exceptions prevent sentry_sdk.capture_exception from firing

High Severity

The new except Exception as e block catches and prints the error but never re-raises it. When the causeAPIError flag is set, base.python.njk wraps the main() call in its own try-except that calls sentry_sdk.capture_exception(e) — but the exception is now silently swallowed inside main(), so it never propagates. This means Sentry never captures the exception, breaking the error-handling test scenarios that depend on it.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think this is entirely accurate as I verified during testing that an error span is being returned from the Python SDK (and not being swallowed as Cursor is saying here) as a result of the generic exception thrown, and is being asserted correctly within the testing framework (example below from a test run):

{
    trace_id: '25a8c19c306a42a2b1bd22b34daa3e84',
    span_id: '85d009fd8743fdb6',
    parent_span_id: '905cfffa695c1f38',
    same_process_as_parent: true,
    op: 'gen_ai.execute_tool',
    description: 'execute_tool read_file',
    start_timestamp: '2026-03-06T16:13:37.239475Z',
    timestamp: '2026-03-06T16:13:37.240453Z',
    origin: 'auto.ai.pydantic_ai',
    status: 'internal_error',
    tags: { status: 'internal_error' },
    data: {
      'thread.id': '8372809984',
      'thread.name': 'MainThread',
      'gen_ai.operation.name': 'execute_tool',
      'gen_ai.tool.type': 'function',
      'gen_ai.tool.name': 'read_file',
      'gen_ai.agent.name': 'file_assistant',
      'gen_ai.tool.input': '{"path": "/nonexistent/file.txt"}'
    }
  }

{% if not loop.last %}
print() # Blank line between turns
{% endif %}
Expand Down
Loading