Skip to content

Conversation

@npage902
Copy link
Contributor

Replaces #33618

Description: Fixes the bug in the load() function where secret placeholders in plain dicts were not replaced, even if they match a key in secrets_map, and adds a test case.

Example:

obj = {"api_key": "__SECRET_API_KEY__"}
secret_key = "secret_key_1234"
secrets_map = {"__SECRET_API_KEY__": secret_key}
result = load(obj, secrets_map=secrets_map)

Before this change, printing api_key in result would output "__SECRET_API_KEY__". Now, it will properly output "secret_key_1234".

Issue: Fixes #31804

Dependencies: None

make format, make lint, and make test have all passed on my machine.

@npage902 npage902 requested a review from eyurtsev as a code owner October 26, 2025 18:53
@github-actions github-actions bot added core Related to the package `langchain-core` langchain Related to the package `langchain` fix labels Oct 26, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 26, 2025

CodSpeed Performance Report

Merging #33678 will not alter performance

Comparing npage902:npage902/fix-load-secrets-map (9d15ff9) with master (9383b78)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched
⏩ 21 skipped1

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@npage902
Copy link
Contributor Author

Apologies for any confusion thanks to my last PR. Now, hopefully everything should be working fine. I'm still learning how to do open source contributions, so please let me know if there are any issues.

@mdrxy mdrxy changed the title fix(core): applied secrets_map in load() to plain string values fix(core): applied secrets_map in load to plain string values Nov 7, 2025
@github-actions github-actions bot added fix and removed fix labels Nov 7, 2025
@mdrxy mdrxy requested a review from Copilot November 7, 2025 21:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for string-based secret placeholders in the load() function, allowing secrets to be referenced directly as string values (e.g., "__SECRET_API_KEY__") in addition to the existing structured secret format ({"lc": 1, "type": "secret", "id": ["KEY"]}).

Key Changes:

  • Enhanced _load() function to check if string values match keys in secrets_map and replace them with the corresponding secret values
  • Added a test case demonstrating the new string secret replacement functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
libs/core/langchain_core/load/load.py Adds string placeholder support by checking if any string value in the object tree matches a key in secrets_map and replacing it with the secret value
libs/langchain/tests/unit_tests/load/test_load.py Adds basic test case for the new string secrets feature with a simple dictionary example

@mdrxy mdrxy merged commit cc3af82 into langchain-ai:master Nov 7, 2025
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Related to the package `langchain-core` fix langchain Related to the package `langchain` langchain-classic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

load() does not apply secrets_map to plain string values

2 participants