<@ULVA73B9P> In the generic Secret block, what is ...
# ask-marvin
w
@Marvin In the generic Secret block, what is the difference between password, string, and json? When would I use each type?
m
thought for 148.8 seconds
In Prefect’s generic
Secret
block, password, string, and JSON are mostly different input modes / schemas for the same secret value. Short version: - password → use for a secret string you want entered as a masked value - string → use for a plain string value - JSON → use for structured data like dicts/lists, or any JSON-serializable value Example docs: - Blocks docs What each means 1. password - Accepts a string - Shown in the UI as a masked password field - Best for: - API keys - tokens - passwords - client secrets Example:
Copy code
python
from prefect.blocks.system import Secret

secret = Secret(value="super-secret-token")
print(secret.get())
Use this when the value is just one sensitive string and you want the UI to treat it like a password. 2. string - Also accepts a string - Shown in the UI as a normal text field - Best for: - connection strings - hostnames or URLs - non-structured config text - any secret/non-secret single text value Example:
Copy code
python
from prefect.blocks.system import Secret

secret = Secret(value="<postgresql://user:pass@host/db>")
print(secret.get())
Use this when your value is still just text, but not naturally a “password”-style entry. 3. JSON - Accepts JSON-serializable data - Good for: - dictionaries / objects - lists - nested credentials - grouped config Example:
Copy code
python
from prefect.blocks.system import Secret

secret = Secret(value={
    "username": "my-user",
    "password": "my-pass",
    "host": "<http://db.example.com|db.example.com>",
    "port": 5432
})

print(secret.get())
Use this when you want one secret block to hold multiple related values. How to choose Choose based on the shape of the data: - If it’s one secret text value like
abcd1234
password - If it’s one plain text value like a URL or connection string → string - If it’s structured like
{ "api_key": "...", "account_id": "..." }
JSON Important practical note For password and string,
secret.get()
returns a string. For JSON,
secret.get()
returns the structured object, like a dict or list. So this works:
Copy code
python
creds = Secret.load("my-json-secret").get()
print(creds["username"])
while this is more typical for password/string:
Copy code
python
token = Secret.load("my-api-token").get()
Rule of thumb - One value
password
or
string
- Many values
JSON
If you want, I can also show exactly how this looks in the Prefect UI and how to create each one from Python.