Skip to content

fix(py): show prompt calls as their own span with render and generate in the Dev UI - #66

Merged
huangjeff5 merged 4 commits into
mainfrom
fix/py-trace-prompt-span
Nov 10, 2026
Merged

huangjeff5 merged 4 commits into
mainfrom
fix/py-trace-prompt-span

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Calling a prompt now shows in Dev UI traces as its own span, with render and generate under it. Before, the template step was invisible and the model call hung straight off the caller, so you couldn't tell which prompt ran or what it rendered.

greeting = ai.define_prompt(name='greeting_prompt', model='my-model', prompt='Say hi to {{name}}')

@ai.flow(name='prompt_flow')
async def prompt_flow(name: str) -> str:
    return (await greeting(input={'name': name})).text

# --- BEFORE ---
# prompt_flow
# └ generate
#   └ my-model

# --- AFTER ---
# prompt_flow
# └ greeting_prompt          (genkit:type dotprompt)
#   ├ render                 (genkit:type promptTemplate)
#   └ generate
#     └ my-model

Main Changes

  • One span per prompt call, named like the action: __call__ and stream wrap render + generate in a span named with the registry key (greeting_prompt, greeting_prompt.formal, ns/name). Input is the prompt input, output is the ModelResponse. A response with .error marks the span failed; it still returns, same as generate.
  • render shows what the template produced: A render span (type promptTemplate, genkit:metadata:promptName = the same key) records the input and the resulting GenerateActionOptions. prompt.render(), prompt agent turns (define_agent), and both Dev UI runners (/prompt/..., /executable-prompt/...) emit it too.
  • Unnamed prompts skip the prompt span: There is nothing to label it with, so their render and generate sit under the caller. JS has no unnamed prompts.

Behavior changes

No API or return-type changes. Trace shape changes: generate and model spans under a prompt now have the prompt in their genkit:path. Anything filtering exported spans by path will see the extra segment.

Cross-SDK

Span names, genkit:type values, and promptName match JS prompt.ts (including prompt agents rendering through render_prompt so agent turns emit a render span). Two intentional differences from JS:

  • .stream() on define_prompt handles: Python wraps .stream() in the dotprompt span on both ai.define_prompt(...) and ai.prompt(...) handles so the trace tree does not depend on how the caller obtained the prompt handle, whereas JS only wraps ai.prompt('name').stream() (wrapExecutablePromptPromise) and omits the prompt span on definePrompt().stream().
  • File prompt naming (matches Go): All three SDKs name the prompt span after its registered action key; Python and Go (LoadPromptDirFromFS with namespace="") both register file_prompt.prompt as file_prompt without JS's default dotprompt/ namespace prefix, matching ai.prompt('file_prompt') and preserving /prompt/... and /executable-prompt/... action keys.

@huangjeff5
huangjeff5 requested a review from hilariie November 10, 2026 05:10

@cabljac cabljac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with comments

@huangjeff5
huangjeff5 force-pushed the fix/py-trace-prompt-span branch from fd373e5 to 30bfe01 Compare November 10, 2026 19:47
@huangjeff5
huangjeff5 merged commit 1221025 into main Nov 10, 2026
21 checks passed
@huangjeff5
huangjeff5 deleted the fix/py-trace-prompt-span branch November 10, 2026 20:11
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.

2 participants