Skip to content

fix(cli): register --no_capture_message_content option in argparse - #1969

Open
todkarsant wants to merge 3 commits into
openlit:mainfrom
todkarsant:fix/cli-no-capture-message-content
Open

todkarsant wants to merge 3 commits into
openlit:mainfrom
todkarsant:fix/cli-no-capture-message-content

Conversation

@todkarsant

@todkarsant todkarsant commented Nov 19, 2026 •

Copy link
Copy Markdown

Fixes #1962

Summary

  • Register --no_capture_message_content as a store_false action alongside the existing --capture_message_content store_true in a mutually-exclusive argparse group
  • When --no_capture_message_content is passed and OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT is not already set, export false to the launched process
  • Reject specifying both --capture_message_content and --no_capture_message_content together
  • When neither flag is given, the env var is left untouched (no change in default behaviour)
  • Add test coverage for all four cases (positive flag, negative flag, no flag, both flags)

Summary by Sourcery

Allow the CLI to explicitly enable or disable message-content capture without changing existing defaults or environment precedence.

New Features:

  • Add explicit --no_capture_message_content support alongside the existing positive flag.

Bug Fixes:

  • Ensure CLI negation correctly exports false while preserving existing environment-variable precedence and default behavior.

Enhancements:

  • Document both enable and disable options for message-content capture.

Documentation:

  • Update SDK configuration documentation to describe the positive and negative message-content capture flags.

Tests:

  • Add coverage for positive, negative, omitted, conflicting, and environment-precedence flag scenarios.

The CLI config declared has_negation=True for capture_message_content
but parse_arguments() only registered the positive --capture_message_content
store_true action.  Passing --no_capture_message_content caused argparse to
exit with "unrecognized arguments".

Register both the positive and negative forms in a mutually-exclusive group
so that:
- --no_capture_message_content is accepted and exports
  OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=false
- --capture_message_content still works as before
- Specifying both flags together is rejected
- When neither flag is given the env var is left untouched

Fixes openlit#1962
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implementation

Register mutually exclusive positive and negative capture flags, and export explicit boolean values while preserving environment-variable precedence.

  • sdk/python/src/openlit/cli/main.py L67-87, L119-125, L130-140

Documentation

Document the negative capture flag and clarify that either CLI form enables or disables content tracing.

  • docs/latest/sdk/configuration.mdx L43

Tests

Cover parsing, environment export, omitted flags, conflicting flags, and environment-variable precedence for capture-content options.

  • sdk/python/tests/test_cli_negation_flag.py L1-97

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@todkarsant

Copy link
Copy Markdown
Author

@AmanAgarwal041 Could you review this? Fixes the CLI --no_capture_message_content option that was declared (has_negation=True in config) but never registered in argparse. Thanks!

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Fix CLI support for disabling message content capture

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Accept --no_capture_message_content and reject conflicting capture flags.
• Export false when explicitly disabled, while preserving environment-variable precedence and the
 no-flag default.
• Test flag parsing and environment export for positive, negative, absent, and conflicting flags.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed CLI state is propagated through one environment variable into OpenlitConfig and then passed to instrumentors that decide whether LLM message content is recorded.
  • These are implementation hops of the same bounded configuration behavior, not independent capabilities or scopes.
  • The selected boolean controls the same end-to-end content-capture behavior across the CLI, startup environment, global configuration, and instrumentor consumers; those layers do not constitute separate functional scopes.
Sources

sdk/python/src/openlit/cli/main.py[82-85]

                group.add_argument(
                    neg_arg, action="store_false", default=None, help=neg_help,
                    dest=param_name,
                )

sdk/python/src/openlit/cli/main.py[136-142]

                    if (
                        cli_value is False
                        and config.get("default") is True
                        and not config.get("has_negation")
                    ):
                        continue
                    os.environ[env_var] = "true" if cli_value else "false"
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before: boolean CLI options used a single store_true path, where the absent option was represented by argparse's ordinary false default and the exporter had to distinguish that from the configured default.
  • After: the changed logic introduces explicit positive, explicit negative, and absent states using mutually exclusive arguments with default=None, plus an environment-precedence branch that treats empty values specially.
  • New correctness condition: explicit enable and explicit disable must remain distinguishable from omission while preserving non-empty environment-variable precedence and producing the correct downstream boolean.
  • The downstream configuration and instrumentor plumbing are established infrastructure; the new interaction is the CLI/default/environment state matrix, not the existence of those helpers.
Sources

sdk/python/src/openlit/cli/main.py[82-85]

                group.add_argument(
                    neg_arg, action="store_false", default=None, help=neg_help,
                    dest=param_name,
                )

sdk/python/src/openlit/cli/main.py[136-142]

                    if (
                        cli_value is False
                        and config.get("default") is True
                        and not config.get("has_negation")
                    ):
                        continue
                    os.environ[env_var] = "true" if cli_value else "false"
Potential damage 🔴 High 🩹 Confidentiality

  • If an explicit disable is incorrectly converted to true, prompts and model responses that the operator intentionally excluded can be placed in telemetry and exported to the configured monitoring backend.
  • This is a confidentiality failure within the affected content-capture capability.
  • The source documents content tracing as an opt-in/opt-out behavior, and the setting reaches downstream instrumentors.
  • Equal business importance is assumed; the concrete consequence comes from unintended content disclosure, not business criticality.
  • Reverting the CLI code prevents future incorrect selections, but does not retract spans already exported.
  • Recovery of already transmitted content depends on backend retention and deletion controls not established in the inspected source; manual deletion or compensation may be required.
Sources

sdk/python/src/openlit/cli/main.py[136-142]

                    if (
                        cli_value is False
                        and config.get("default") is True
                        and not config.get("has_negation")
                    ):
                        continue
                    os.environ[env_var] = "true" if cli_value else "false"
Assessed commit 006a61b
Diagram

graph TD
  Config["CLI parameter config"] --> Parser["Argument parser"] --> Flag{"Flag selection"} -->|specified| Existing{"Env already set?"} -->|no| Export["Export flag value"] --> App["Launched application"]
  Flag -->|omitted| App
  Flag -->|both| Error["Argument error"]
  Existing -->|yes| App
Loading
High-Level Assessment

Using argparse's mutually exclusive group and a None default fits the existing config-driven CLI: it distinguishes an explicit negative flag from no flag without changing environment-variable precedence. Manual inspection of raw arguments would duplicate argparse's validation and is unnecessary.

Files changed (2) +129 / -4

Bug fix (1) +32 / -4
main.pyRegister negatable capture flags and honor explicit false +32/-4

Register negatable capture flags and honor explicit false

• Registers positive and negative options in a mutually exclusive group for boolean parameters marked 'has_negation'. Leaves an omitted option as 'None' and exports an explicit 'false' without overwriting an existing environment variable.

sdk/python/src/openlit/cli/main.py

Tests (1) +97 / -0
test_cli_negation_flag.pyCover capture flag parsing and environment precedence +97/-0

Cover capture flag parsing and environment precedence

• Tests positive, negative, absent, and conflicting flags. Verifies environment export and that an existing environment value takes precedence over the negative flag.

sdk/python/tests/test_cli_negation_flag.py

@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit 006a61b

#1962 Bug: Python CLI rejects configured --no_capture_message_content option · 3 of 3 met

# Requirement Status Notes
1 Accept --no_capture_message_content and export false when the configured environment variable is unset ✅ Met The CLI registers the negative option and exports false to OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT.
2 Preserve environment-variable precedence, omitted-flag defaults, and other boolean flags ✅ Met Existing non-empty environment values take precedence; omitting the option leaves the environment untouched, and the existing handling for other boolean flags is unchanged.
3 Reject specifying both positive and negative forms ✅ Met The two options are registered in a mutually exclusive argparse group.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="sdk/python/src/openlit/cli/main.py" line_range="131-136" />
<code_context>
+                    # For has_negation params the argparse default is None, so
+                    # reaching here with False means the user explicitly passed
+                    # the --no_<flag> form and we must honour it.
+                    if (
+                        cli_value is False
+                        and config.get("default") is True
+                        and not config.get("has_negation")
+                    ):
                         continue
                     os.environ[env_var] = "true" if cli_value else "false"
                 else:
</code_context>
<issue_to_address>
**Empty setting re-enables content capture**

When the CLI is invoked with `--no_capture_message_content` while `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` is present but empty, `set_environment_from_cli_args` skips exporting `false` because the variable exists, while `build_config_from_environment` ignores its empty value and `openlit.init` retains the default `True`; message content is captured despite the explicit opt-out.

Treat an empty environment value as unset for CLI precedence, or otherwise ensure it cannot restore the default capture behavior after an explicit opt-out.
</issue_to_address>

### Comment 2
<location path="sdk/python/src/openlit/cli/main.py" line_range="72" />
<code_context>
+                # enable or disable the behaviour.  Using a mutually-exclusive
+                # group means argparse will reject contradictory combos like
+                # ``--capture_message_content --no_capture_message_content``.
+                neg_arg = f"--no_{param_name}"
+                neg_help = (
+                    f"Disable {config.get('cli_help', '').lower()} "
</code_context>
<issue_to_address>
**Disable option is undocumented**

When a user consults the configuration docs to disable content capture from the CLI, the configuration docs list only `--capture_message_content`, so users looking for a CLI way to disable content capture cannot discover the new negative option.

Document `--no_capture_message_content` in the SDK configuration docs.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: sdk/python/src/openlit/cli/main.py:136


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread sdk/python/src/openlit/cli/main.py Resolved
Comment thread sdk/python/src/openlit/cli/main.py Resolved
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

When OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT was present
but empty, the CLI skipped exporting 'false' for --no_capture_message_content
because the variable technically existed. The empty value was then ignored
downstream, silently re-enabling content capture.
@todkarsant

Copy link
Copy Markdown
Author

Addressed the Sourcery finding in 292293c:

When OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT was present but empty, set_environment_from_cli_args skipped exporting because the variable technically existed. The empty value was then ignored downstream, re-enabling content capture despite the explicit --no_capture_message_content opt-out.

Fixed by treating an empty env var as unset: if env_var not in os.environ or os.environ[env_var] == "".

Re the docs comment: the --no_capture_message_content flag is auto-documented via argparse --help. Formal SDK config docs update can be a follow-up.

@sourcery-ai sourcery-ai Bot 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.

New gaps against the linked issues

Comment thread sdk/python/src/openlit/cli/main.py Resolved
Restrict the empty-environment-variable-as-unset logic to boolean
parameters with a has_negation variant.  Previously all env vars
were affected, which could let CLI args silently overwrite an
intentionally empty setting.  Also document --no_capture_message_content
in the SDK configuration table.
@mintlify

mintlify Bot commented Nov 20, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 006a61b.

Approve preview

@sourcery-ai sourcery-ai Bot 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.

Sourcery assessment

Approved.

This branch was previously deployed

1 inactive (outdated) deployment
release-notes — 22e8e807 Deployed Nov 19, 2026 by todkarsant via Normalize / Conventional title #858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Python CLI rejects configured --no_capture_message_content option

1 participant