Nicholas Pini
05/07/2026, 3:53 PM{
"secret_key_1": "123",
"secret_key_2": "456"
}
is it possible to set two env variable in the job variables of a deployment using templating, one variable set to secret_key_1 and the other to secret_key_2?Marvin
05/07/2026, 3:53 PMMarvin
05/07/2026, 3:53 PMNicholas Pini
05/07/2026, 3:54 PM{
"secret_key_1": "123",
"secret_key_2": "456"
}
is it possible to set two env variable in the job variables of a deployment using templating, one variable set to secret_key_1 and the other to secret_key_2?Marvin
05/07/2026, 3:54 PMMarvin
05/07/2026, 3:56 PMSecret block the way you described.
If you save a Secret block with JSON like:
json
{ "secret_key_1": "123", "secret_key_2": "456" }
you can reference the whole secret value in templating, but you generally can't split it into separate env vars by key in deployment job_variables.
So this kind of thing is not supported for a Secret block:
yaml
job_variables:
env:
VAR1: "{{ prefect.blocks.secret.my-secret.secret_key_1 }}"
VAR2: "{{ prefect.blocks.secret.my-secret.secret_key_2 }}"
What does work is referencing the entire secret:
yaml
job_variables:
env:
MY_SECRET_JSON: "{{ prefect.blocks.secret.my-secret }}"
Then your code can parse it at runtime.
Recommended options:
1. Use separate Secret blocks
One block per env var:
yaml
job_variables:
env:
VAR1: "{{ prefect.blocks.secret.secret-key-1 }}"
VAR2: "{{ prefect.blocks.secret.secret-key-2 }}"
2. Use a custom block with structured fields
This is the best option if you want multiple named values and templated access to each field.
3. Store the JSON in one Secret and parse it inside the flow
Example:
python
import json
from prefect import flow
from prefect.blocks.system import Secret
@flow
def my_flow():
secret = Secret.load("my-secret").get()
# depending on how you stored it, this may already be a dict
if isinstance(secret, str):
secret = json.loads(secret)
var1 = secret["secret_key_1"]
var2 = secret["secret_key_2"]
A useful doc entry for block references in templating is here:
Templating options in prefect.yaml
If you want, I can show you the exact prefect.yaml / deployment job_variables syntax for:
- separate Secret blocks, or
- a custom block with two fieldsNate
05/07/2026, 6:13 PMNate
05/07/2026, 6:28 PMjob_variables:
env:
VAR1: "{{ prefect.blocks.secret.my-secret.value.secret_key_1 }}"
VAR2: "{{ prefect.blocks.secret.my-secret.value.secret_key_2 }}"
The .value. is required because Secret is a single-value block — the resolver auto-unwraps the top level (so {{ ...my-secret }} returns the JSON dict directly), but to drill into a key
you address it through .value.<key>. Storing the JSON as a dict (not a stringified blob) is what makes the keypath resolvable.Marvin
05/07/2026, 6:29 PMMarvin
05/07/2026, 6:29 PMSecret block's value is stored as a dict/object, then you can template individual keys in deployment job_variables using `.value.<key>`:
yaml
job_variables:
env:
VAR1: "{{ prefect.blocks.secret.my-secret.value.secret_key_1 }}"
VAR2: "{{ prefect.blocks.secret.my-secret.value.secret_key_2 }}"
A few important notes:
- This works when the secret is stored as a structured JSON object / dict, not a JSON string blob.
- {{ prefect.blocks.secret.my-secret }} resolves the whole secret value.
- To access nested fields, use .value.<key>.
So for a secret like:
json
{
"secret_key_1": "123",
"secret_key_2": "456"
}
you can set two env vars exactly as above.
If your keys are nested, the same pattern applies:
yaml
job_variables:
env:
VAR1: "{{ prefect.blocks.secret.my-secret.value.parent.child }}"
If you'd like, I can also help verify the exact syntax for your deployment style:
- prefect.yaml
- Python .deploy(...)
- or via the UI job variables field