Skip to content

fix: Ignore empty or invalid integer environment variables - #825

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
braintrustdata:mainfrom
RaphaelFakhri:fix/invalid-int-env-vars
Sep 29, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 1 commit into
braintrustdata:mainfrom
RaphaelFakhri:fix/invalid-int-env-vars

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Summary

Empty or non-numeric values for integer environment variables no longer raise. The SDK now keeps the default, matching the other BRAINTRUST_* variables that already go through BraintrustEnv.

Six variables in py/src/braintrust/logger.py were parsed with a bare int(os.environ.get(...)):

  • BRAINTRUST_PROMPT_CACHE_MEMORY_MAX_SIZE, BRAINTRUST_PROMPT_CACHE_DISK_MAX_SIZE, BRAINTRUST_PARAMETERS_CACHE_MEMORY_MAX_SIZE and BRAINTRUST_PARAMETERS_CACHE_DISK_MAX_SIZE are read in BraintrustState.__init__. A value such as BRAINTRUST_PROMPT_CACHE_DISK_MAX_SIZE= (declared but empty in a .env template or CI config) raises ValueError when the global state is created, so braintrust.init and the first traced call fail.
  • BRAINTRUST_MAX_GENERATOR_ITEMS is read inside the @traced generator wrappers. An empty or invalid value raises ValueError from the user's own generator on its first iteration.

This change adds BraintrustEnv entries for these variables and reads them with .get(default), which returns the default for empty, whitespace-only and non-numeric values.

Test plan

  • Added test_traced_generators_ignore_invalid_max_items_env (sync and async generators, three invalid values) and test_state_ignores_invalid_cache_size_env (four variables, two invalid values) in py/src/braintrust/test_logger.py.
  • Before the change, 11 of the 25 selected tests fail with ValueError. After the change, all 25 pass, and the full test_logger.py run reports 219 passed and 4 skipped.
cd py && python -m pytest src/braintrust/test_logger.py -k "invalid_max_items_env or invalid_cache_size_env or generator"

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit ed5dba4 into braintrustdata:main Sep 29, 2026
83 checks passed
@AbhiPrasad

Copy link
Copy Markdown
Member

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