Why Kavach?
Also known as: why another language motivation reason purpose compare python javascript go rust advantages benefits meaning name armour
● Beginner5 min
There are already hundreds of languages, and many make life easier. Kavach exists for something they weren't built for: AI writes much of today's code, and AI agents now take real actions.
A fair question
Python is quick for scripts, JavaScript runs the web, Go makes servers simple, and Rust and C++ are fast and precise. They are good languages. If one of them serves you well, keep using it: Kavach doesn't try to be a better Python, Rust or Go for everything.
But those languages were designed for people writing code by hand. Nothing in a Python or JavaScript function tells you whether it can touch the network, spend money, or leak a customer's card number.
What changed
- AI writes much of the code, and people review it. Reviewing 300 generated lines is slow, and people miss things.
- AI agents take real actions. They refund orders, change records, send emails and deploy code.
- Companies don't trust those agents yet. Today's guardrails are spread over prompts, glue code and checks added later. None of them is a hard guarantee.
What Kavach does about it
In Kavach, what code is allowed to do is part of the code: the compiler checks it, and the runtime enforces it.
| The question | Usually | In Kavach |
|---|---|---|
| What can this code touch? | Read its whole body, and every library it calls. | The first line says: uses Fs.read. The compiler checks it. See it → |
| Can this AI agent spend too much, or act without a person's yes? | A prompt asks the model nicely; glue code checks, if someone remembered to write it. | limit and approve are checked on every call, outside anything the model can influence. See it → |
| Will the model's answer have the right shape? | Parse its text and hope. | ask<T> gives a value of type T that passed the checks, or an error. See it → |
| Can a card number leak into a log or a prompt? | Code review, and tools that find the leak afterwards. | A secret value that reaches a log, a prompt or JSON doesn't compile. See it → |
| What if the machine dies halfway through a payment? | Build your own retries, and hope nothing runs twice. | A journal: after a restart the work finishes, and nothing is paid twice. See it → |
| Is this code an AI wrote correct? | Read all 300 lines. | Read the signature: what it takes, gives, may fail with, may touch, and promises. See it → |
An AI shopping assistant, for example. Elsewhere its budget would live in a prompt; here it lives in the code:
type StoreError = OutOfStock | Denied(reason: String)
capability Store {
fn buy(item: String, price: Int) ! StoreError
}
type TestStore: Store {
fn buy(self, item: String, price: Int) ! StoreError {
print("bought {item} for {price}")
}
}
agent Shopper {
can Store.buy
limit Store.buy {
price <= 2_000
sum(price) <= 3_000 per day
count <= 3 per hour
}
on order(item: String, price: Int) ! StoreError {
try Store.buy(item, price)
}
}
fn main() {
const bot = Shopper.start(Store: TestStore())
for r in [(item: "rice", price: 900), (item: "laptop", price: 45_000), (item: "pan", price: 1_500), (item: "tea", price: 800)] {
bot.order(r.item, r.price) catch e => print("not bought {r.item}: {e}")
}
}The program ran and printed:
kavach run uc-shopping.kav
bought rice for 900not bought laptop: Denied(reason: "limit broken: price <= 2_000")bought pan for 1500not bought tea: Denied(reason: "limit broken: sum(price) <= 3_000 per day")
And an everyday language too
Speed and ease are not the reason to switch, but you don't give them up:
- Fast: compiled to native code with no garbage collector, measured against C++ and Python on the Benchmarks page, with the steps to check every number yourself.
- Easy to learn: a small language, types worked out for you, and errors that say what to write instead.
- Fewer traps:
0.1 + 0.2is0.3, and a number too big stops with a message instead of turning wrong (Classic Mistakes, Fixed). - Script or program: run a file with
kavach runlike a script, or build one executable to ship. - Works with what you have: Kavach calls C libraries, and Python, Node.js or Go can call a Kavach library, so you can adopt it one part at a time. Calling Python and JavaScript packages directly comes later.
The name
Kavach (कवच) means armour in Hindi: the protection a warrior wears. The language is armour around code that acts in the world, so a mistake, whether a person's or an AI's, is stopped before it does harm.
Kavach is young: it is in its first phase, before its first public release. Learn it, try it and build tools with it now; see Who Kavach Is For for what comes later.