Skip to content

Allow Prompts.get_all() without a label, to batch-fetch the latest version of every prompt #959

Description

@posthog

Problem Statement

Prompts.get_all() requires a label. An app that wants the current version of every prompt has no batch entry point, so it falls back to one get() per prompt.

That is the common shape for teams that do not use labels at all, and it is the shape get_all was added to remove. Each prompt costs one request against the prompt fetch rate limits, and the requests are made on every cache cycle.

The server side already supports it. GET /api/environments/@current/llm_prompts/ returns the latest version of every prompt when label is omitted, and PostHog/posthog#100690 makes that path report $llm_prompt_fetched the same way the labeled path does.

Solution Brainstorm

Make label optional:

def get_all(self, *, label: Optional[str] = None) -> Dict[str, PromptResult]: ...
  • Without label, every prompt comes back at its latest version, cached under the same key get(name) reads, so a later get(name) is a cache hit within the TTL.
  • With label, behavior is unchanged.
  • The change is additive, so existing get_all(label=...) callers are unaffected. It does touch references/public_api_snapshot.txt.

The label-compatibility guards in get_all (the absent and "no row resolved the label" errors) only apply when a label was requested. They exist to catch an older server that ignores the label parameter, and the unlabeled list has always returned latest versions, so the unlabeled path skips them.

A working patch along these lines passes the existing posthog/test/ai/test_prompts.py suite unchanged. Happy to open a PR once a maintainer agrees on the shape, per the "Public API changes" rule in CONTRIBUTING.md.

Filed by a PostHog agent, from an inbox report about prompt-management callers hitting the per-prompt rate limits.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions