Skip to content
Kavachकवच

Secrets

Also known as: secret password token api key pii redact leak data loss prevention sensitive credentials

● Intermediate4 minBefore this: RecordsSpec 8.7

Mark a field secret, and the compiler follows its value everywhere: it can't reach print, text, prompts, errors, logs or JSON unless you write reveal().

type Login {
    user: String
    secret password: String
}

fn main() {
    const login = Login(user: "asha", password: "mango-42")
    print(login.password)
}

The compiler refused the program:

kavach run secret-print.kav

error: `password` is secret, so it can't go into `print`; use `reveal(…)` if you really mean to
secret-print.kav: Kavach code, then what running it prints

A secret value must not flow into:

  • print, debug or text with {…} in it,
  • a prompt for ask, where it would leave for the model's provider,
  • an error message, the audit log or any log,
  • JSON: json.stringify of a record with a secret field is refused.

Into a prompt, refused before the program runs:

type Customer {
    name: String
    secret card: String
}

type Answer {
    ok: Bool
}

agent Helper {
    can Ai

    on check(c: Customer) ! Error {
        const a = try ask<Answer>("Is card {c.card} valid for {c.name}?")
    }
}

The compiler refused the program:

kavach run secret.kav

error: `card` is secret, so it can't go into text; use `reveal(…)` if you really mean to
secret.kav: Kavach code, then what running it prints

A card number in a prompt is a leak to a third party; a token in a log is a leak to everyone who reads logs. Kavach stops both when compiling, not after the leak.

A value read from the environment with env(name) is a secret too, since keys and passwords usually come that way: see Environment Variables.

One page for each form

What Kavach does for you

  • Secrets stay secret

    A secret prints as <secret> and can't reach logs or messages unless you reveal it on purpose.

    spec 8.7

Check yourself

QUIZ 1 / 1pick one
You really must show part of a secret once. What do you write?