feat(ai): expose prompt config on fetched prompts - #801
Merged
Conversation
Contributor
Prompt To Fix All With AI### Issue 1
posthog/ai/prompts.py:362
**Cached config shares mutable state**
When a caller mutates a fetched `PromptResult.config`, the shared dictionary stored in `CachedPrompt` is also modified, causing later cache-hit and stale-cache results to return caller-modified model parameters or agent configuration instead of the server-provided version.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "chore: add changeset" | Re-trigger Greptile |
Contributor
posthog-python Compliance ReportDate: 2026-07-30 08:53:30 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
marandaneto
approved these changes
Jul 30, 2026
6 tasks
This was referenced Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
PostHog prompt versions can now store a
configobject next to the prompt content (PostHog/posthog#74264): model parameters, tools, or any agent configuration, versioned with the prompt and returned by the fetch endpoint. The SDK parses API responses into typed objects, so without this change the field is fetched and then thrown away.With this change:
PromptResultgainsconfig(object orNone),CachedPromptstores it so cache hits and the stale-cache fallback keep it, and servers that don't send the field (or send an unexpected shape) read asNone. The hardcodedfallbackstring has no config, hence the defensive access in the example.💚 How did you test it?
Five new tests in
test_prompts.py: config surviving the API fetch and a cache hit, the stale-cache path preserving it, and a parameterized matrix for responses where config is absent, null, or a non-object (all read asNone). Full file (67 tests) green, ruff clean.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code authored this under my direction, as the SDK follow-up to PostHog/posthog#74264. The changeset file was written manually in
.sampo/changesets/rather than via interactivesampo add. Docs for the config feature land separately on posthog.com once both SDKs support it.