Repository navigation
test: expect flattened metadata keys for v5 - #2001
Conversation
Co-authored-by: hassieb.pakzad <hassieb.pakzad@clickhouse.com>
|
@claude review |
There was a problem hiding this comment.
Claude Code Review
No review was started: this request came from a bot account. Manual reviews can only be requested by someone with write access to this repository. Ask a maintainer to comment @claude review, or have your automation post the comment from a user account with write access.
Tip: disable this comment in your organization's Code Review settings.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d190037b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| assert generation[0].metadata["response_format.type"] == "json_schema" | ||
| assert generation[0].metadata["response_format.json_schema.name"] == "math_response" |
There was a problem hiding this comment.
Preserve the full response-format assertion
Assert the flattened equivalent of the complete response_format, not only its type and name. If the OpenAI instrumentation drops or corrupts strict, the schema properties, required fields, or additionalProperties, this test now passes despite previously verifying the entire object; checking all expected flattened leaf paths and serialized values would retain that regression coverage.
AGENTS.md reference: AGENTS.md:L32-L34
Useful? React with 👍 / 👎.
| assert generation[0].metadata["response_format.type"] == "json_schema" | ||
| assert generation[0].metadata["response_format.json_schema.name"] == "math_response" |
There was a problem hiding this comment.
🟡 nit (optional): Maintainers lose coverage of the recorded json_schema body. The new assertions would still pass if the SDK dropped or mangled schema in response_format metadata. Only response_format.type and response_format.json_schema.name are checked now, though the flattened schema still has string leaves that can be asserted. Fix: also assert a few string-valued schema paths, e.g. metadata["response_format.json_schema.schema.type"] == "object" and metadata["response_format.json_schema.schema.properties.final_answer.type"] == "string".
Why this was flagged
On the base branch, tests/live_provider/test_openai.py compared generation[0].metadata["response_format"] with the full {"type": "json_schema", "json_schema": json_schema}. So a regression in _get_structured_output_metadata / _serialize_openai_value (langfuse/openai.py:250-274) that lost or changed the nested schema would fail the test. After the change, lines 1007-1008 check only two top-level string leaves. Such a regression now passes silently. The PR says arrays and booleans are JSON-stringified at their path, which explains skipping strict and required. It does not explain skipping string leaves like schema.type or schema.properties.final_answer.type, which come back as plain strings at their dotted paths.
Verification: The base test asserted generation[0].metadata["response_format"] == {"type": "json_schema", "json_schema": json_schema}, covering the full schema (test_openai.py lines 961-984). Lines 1007-1008 now assert only response_format.type and response_format.json_schema.name, so a regression that lost the schema would pass silently.
| assert generation[0].metadata["response_format.type"] == "json_schema" | ||
| assert generation[0].metadata["response_format.json_schema.name"] == "math_response" |
There was a problem hiding this comment.
Replacing the full response_format comparison with only type and name lets this test pass if the captured metadata drops json_schema.schema entirely. Keep assertions for short string-valued leaves such as response_format.json_schema.schema.type and response_format.json_schema.schema.properties.final_answer.type. These do not need array or boolean decoding.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/live_provider/test_openai.py
Line: 1007-1008
Comment:
**Actual schema goes unchecked**
Replacing the full `response_format` comparison with only `type` and `name` lets this test pass if the captured metadata drops `json_schema.schema` entirely. Keep assertions for short string-valued leaves such as `response_format.json_schema.schema.type` and `response_format.json_schema.schema.properties.final_answer.type`. These do not need array or boolean decoding.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
What does this PR do?
CI on
mainand on thev5.0.0/v5.0.1release commits fails in three e2e tests withKeyError: 'context'/KeyError: 'response_format'. The release commits only bump the version from 4.18.0 to 5.0.0. For Python SDK 5 and later, the server JSON-decodes per-key metadata and stores nested objects as flattened dotted paths (langfuse/langfuse#18436). The observations API returns those paths as-is, so nested metadata comes back as{"context.nested": ...}, not{"context": {"nested": ...}}. Before the release, pre-release CI still ran as 4.x and never hit this path.This PR changes tests only; there are no SDK changes.
tests/e2e/test_media.py,tests/e2e/test_decorators.py: read and pollmetadata["context.nested"].tests/live_provider/test_openai.py: assert the string-valued pathsresponse_format.typeandresponse_format.json_schema.name, and dropexpand_metadata="response_format", which no longer matches a top-level key. Arrays and booleans are JSON-stringified at their path, so the test doesn't assert on them.tests/e2e/test_core_sdk.py: remove thexfailmarker ontest_create_score_with_custom_timestamp. The platform release it waited for has shipped, and the test XPASSes on current CI.Failing run this fixes: https://github.com/langfuse/langfuse-python/actions/runs/38553271207
Type of change
Verification
I didn't run e2e or live-provider tests locally: the local server's seeded API key was rejected and no
OPENAI_API_KEYwas available. This PR's CI E2E shards and live-provider job are the verification.Checklist
code_review.md..env.templateif needed.The PR appears safe to merge, with a non-blocking gap in the OpenAI schema checks.
Summary
Updates tests to expect flattened observation metadata for SDK v5.
One non-blocking concern remains: the OpenAI test no longer checks any fields inside the actual response schema.
hassiebp explicitly states that array and boolean assertions were intentionally dropped because those values are JSON-stringified.
Reviews (1) · Last reviewed commit: "test: expect flattened metadata keys for..." · Reviewed by Greptile