Skip to content

Commit f101c75

Browse files
authored
docs: how to pass runtime secrets (#24450)
1 parent 372c27f commit f101c75

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

docs/docs/how_to/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This highlights functionality that is core to using LangChain.
4444
- [How to: inspect runnables](/docs/how_to/inspect)
4545
- [How to: add fallbacks to a runnable](/docs/how_to/fallbacks)
4646
- [How to: migrate chains to LCEL](/docs/how_to/migrate_chains)
47+
- [How to: pass runtime secrets to a runnable](/docs/how_to/runnable_runtime_secrets)
4748

4849
## Components
4950

@@ -199,6 +200,7 @@ LangChain [Tools](/docs/concepts/#tools) contain a description of the tool (to p
199200
- [How to: return artifacts from a tool](/docs/how_to/tool_artifacts/)
200201
- [How to: convert Runnables to tools](/docs/how_to/convert_runnable_to_tool)
201202
- [How to: add ad-hoc tool calling capability to models](/docs/how_to/tools_prompting)
203+
- [How to: pass in runtime secrets](/docs/how_to/runnable_runtime_secrets)
202204

203205
### Multimodal
204206

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "6fcd2994-0092-4fa3-9bb1-c9c84babadc5",
6+
"metadata": {},
7+
"source": [
8+
"# How to pass runtime secrets to runnables\n",
9+
"\n",
10+
":::info Requires `langchain-core >= 0.2.22`\n",
11+
"\n",
12+
":::\n",
13+
"\n",
14+
"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:"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 6,
20+
"id": "92e42e91-c277-49de-aa7a-dfb5c993c817",
21+
"metadata": {},
22+
"outputs": [
23+
{
24+
"data": {
25+
"text/plain": [
26+
"7"
27+
]
28+
},
29+
"execution_count": 6,
30+
"metadata": {},
31+
"output_type": "execute_result"
32+
}
33+
],
34+
"source": [
35+
"from langchain_core.runnables import RunnableConfig\n",
36+
"from langchain_core.tools import tool\n",
37+
"\n",
38+
"\n",
39+
"@tool\n",
40+
"def foo(x: int, config: RunnableConfig) -> int:\n",
41+
" \"\"\"Sum x and a secret int\"\"\"\n",
42+
" return x + config[\"configurable\"][\"__top_secret_int\"]\n",
43+
"\n",
44+
"\n",
45+
"foo.invoke({\"x\": 5}, {\"configurable\": {\"__top_secret_int\": 2, \"traced_key\": \"bar\"}})"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"id": "ae3a4fb9-2ce7-46b2-b654-35dff0ae7197",
51+
"metadata": {},
52+
"source": [
53+
"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"
54+
]
55+
}
56+
],
57+
"metadata": {
58+
"kernelspec": {
59+
"display_name": "poetry-venv-311",
60+
"language": "python",
61+
"name": "poetry-venv-311"
62+
},
63+
"language_info": {
64+
"codemirror_mode": {
65+
"name": "ipython",
66+
"version": 3
67+
},
68+
"file_extension": ".py",
69+
"mimetype": "text/x-python",
70+
"name": "python",
71+
"nbconvert_exporter": "python",
72+
"pygments_lexer": "ipython3",
73+
"version": "3.11.9"
74+
}
75+
},
76+
"nbformat": 4,
77+
"nbformat_minor": 5
78+
}

0 commit comments

Comments
 (0)