-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: how to pass runtime secrets (#24450)
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6fcd2994-0092-4fa3-9bb1-c9c84babadc5", | ||
"metadata": {}, | ||
"source": [ | ||
"# How to pass runtime secrets to runnables\n", | ||
"\n", | ||
":::info Requires `langchain-core >= 0.2.22`\n", | ||
"\n", | ||
":::\n", | ||
"\n", | ||
"We can pass in secrets to our runnables at runtime using the `RunnableConfig`. Specifically we can pass in secrets with a `__` prefix to the `configurable` field. This will ensure that these secrets aren't traced as part of the invocation:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "92e42e91-c277-49de-aa7a-dfb5c993c817", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"7" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from langchain_core.runnables import RunnableConfig\n", | ||
"from langchain_core.tools import tool\n", | ||
"\n", | ||
"\n", | ||
"@tool\n", | ||
"def foo(x: int, config: RunnableConfig) -> int:\n", | ||
" \"\"\"Sum x and a secret int\"\"\"\n", | ||
" return x + config[\"configurable\"][\"__top_secret_int\"]\n", | ||
"\n", | ||
"\n", | ||
"foo.invoke({\"x\": 5}, {\"configurable\": {\"__top_secret_int\": 2, \"traced_key\": \"bar\"}})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ae3a4fb9-2ce7-46b2-b654-35dff0ae7197", | ||
"metadata": {}, | ||
"source": [ | ||
"Looking at the LangSmith trace for this run, we can see that \"traced_key\" was recorded (as part of Metadata) while our secret int was not: https://smith.langchain.com/public/aa7e3289-49ca-422d-a408-f6b927210170/r" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "poetry-venv-311", | ||
"language": "python", | ||
"name": "poetry-venv-311" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |