# Pack validation

> Kore checks your datapack before writing it and fails the build on a mistyped command, a missing function or a broken tag, instead of letting the game skip it.

Updated 2026-12-03. Canonical: https://kore.ayfri.com/docs/guides/validation

A typo in a function id doesn't stop a datapack from loading: the game skips the command and the feature silently does
nothing. Kore catches it when the pack is written:

```kotlin
dataPack("my_pack") {
	function("main") {
		function("mian") // typo
	}
}.generate()
```

```
Datapack 'my_pack' failed validation with 1 problem(s):
[undefined-reference] function my_pack:main, line 1: calls `my_pack:mian`, which the pack never defines, did you mean `my_pack:main`?
Put `# kore:ignore <check>` above a line, add the namespaces of other packs to `externalNamespaces` or their folders to `knownPacks`, or change the check in `configuration { validation { } }`.
```

Validation is on by default and runs after the [optimization passes](https://kore.ayfri.com/docs/guides/optimization.md), in every output path. An
error throws a `PackValidationException` listing every problem, the rest is logged. `pack.validate()` returns the
`Diagnostic` list instead, without logging or throwing.

## Check someone else's pack

The same rules run on a pack that wasn't built with Kore, a folder or a `.zip`:

```kotlin
val diagnostics = Validation.validatePack("my_pack.zip")
```

It also takes a `Path` or, for the browser, a `Map<String, String>` of path to content, and a [settings](#settings) lambda.

## The rules

Every rule has three modes, `ERROR`, `WARNING` or `OFF`, and starts in its Default one. A rule at `OFF` doesn't run, see the
[opt-in rules](#opt-in-rules).

| Id                    | Default | Catches                                                                                              |
|-----------------------|---------|------------------------------------------------------------------------------------------------------|
| `command-syntax`      | error   | A command the game can't parse, or a last line ending with `\`                                       |
| `invalid-json`        | error   | A JSON file the game skips, trailing comma included (external packs only)                            |
| `invalid-path`        | error   | A namespace or path with a character outside `a-z 0-9 _ . -` (and `/` in a path)                     |
| `macro`               | error   | A `$` line without `$(variable)`, or a macro function called without one of its variables            |
| `pack-mcmeta`         | error   | A `pack.mcmeta` the game can't read                                                                  |
| `undeclared-symbol`   | warning | A scoreboard objective, team or bossbar that is used and never created                               |
| `undefined-reference` | error   | A function, tag, advancement, predicate, loot table, item modifier or recipe the pack never defines  |
| `unknown-command`     | off     | A command word the game doesn't have, at the start of a line or after `run`                          |
| `unknown-vanilla-id`  | off     | A `minecraft:` block, item, entity type, mob effect or tag of them the game doesn't have             |

`undefined-reference` only checks the namespaces the pack **owns** (it defines a function or a non-tag resource there), so
another pack, a library tag or `minecraft` is never reported.

### Macro line without a variable

```kotlin
function("greet") { addLine("\$say hi") }
```

```
[macro] function my_pack:greet, line 1: starts with `$` but uses no `$(variable)`, the game drops the whole function
```

Add the variable (`"\$say hi \$(name)"`) or drop the `$`. The opposite mistake, `say $(name)`, is a warning.

### Bad command syntax

```kotlin
function("main") { addLine("scoreboard player add @s kills 1") }
```

```
[command-syntax] function my_pack:main, line 1: column 12: expected `objectives` or `players`, found `player`, did you mean `players`?
```

The command is read against the command tree of Minecraft 26.3. An unknown command word is left to
[`unknown-command`](#opt-in-rules), since mods add commands, but a leading `/` is always reported.

### Objective never created

```kotlin
load { scoreboard.objectives.add("kills") }
function("main") { scoreboard.players.add(allPlayers(), "kils", 1) }
```

```
[undeclared-symbol] function my_pack:main, line 1: uses the objective `kils`, which the pack never creates, did you mean `kills`?
```

It stays silent for a kind the pack never creates at all, and for macro names.

### pack.mcmeta

```json
{"pack": {"description": "My pack", "pack_format": 121}}
```

```
[pack-mcmeta] file pack.mcmeta: has no `min_format`, the game can't read the format of the pack and treats it as incompatible
[pack-mcmeta] file pack.mcmeta: has no `max_format`, the game can't read the format of the pack and treats it as incompatible
```

Declare `"min_format": 121, "max_format": 121`. A Kore pack writes this file for you.

### Opt-in rules

An off rule runs once it has a mode:

```kotlin
validation {
	this[UnknownCommandCheck] = Severity.ERROR
	this[UnknownVanillaIdCheck] = Severity.WARNING
}
function("main") {
	addLine("tellrw @a \"hi\"")
	addLine("give @s minecraft:diamnd_sword")
}
```

```
[unknown-command] function my_pack:main, line 1: column 1: unknown command `tellrw` in Minecraft 26.3, did you mean `tellraw`?
[unknown-vanilla-id] function my_pack:main, line 2: uses the item `minecraft:diamnd_sword`, which doesn't exist in Minecraft 26.3, did you mean `minecraft:diamond_sword`?
```

Fix the word, or keep `unknown-command` off on a modded server (`# kore:ignore unknown-command` silences one line).
`unknown-vanilla-id` reads an id only where the registry is certain: `setblock`, `give`, `summon`, selector types, tags,
loot tables and recipes.

## Settings

```kotlin
dataPack("my_pack") {
	configuration {
		validation {
			this[UndefinedReferenceCheck] = Severity.ERROR    // fails the build
			this[UndeclaredSymbolCheck] = Severity.WARNING    // logged
			this[InvalidPathCheck] = Severity.OFF             // doesn't run, like `this -= InvalidPathCheck`
			this += NoTodoLines                               // add your own
			externalNamespaces += "bs"                        // never report a missing id of it
			knownPacks += Path("libs/bookshelf.zip")          // its ids count as defined
			enabled = false                                   // off
		}
	}
}
```

- Only an `ERROR` fails the build.
- A mode replaces only the diagnostics at the default severity of their check: `this[CommandSyntaxCheck] = Severity.WARNING`
  keeps its `INFO` about a pack of another version an `INFO`. For an off rule that is every diagnostic.
- `externalNamespaces` is for a library you override, else its namespace looks owned.
- `knownPacks` also counts their objectives, teams and bossbars as declared, like the packs of `mergeWithPacks`, whose own files
  aren't checked. A pack imported with [bindings](https://kore.ayfri.com/docs/advanced/bindings.md) is one.
- A check that throws becomes one warning (`check crashed: ...`) and the build goes on.

## Silencing a problem

```kotlin
function("main") {
	comment("kore:ignore undefined-reference")  // the line below, several ids allowed
	function("generated_later")
}

function("legacy") {
	comment("kore:ignore-file macro")           // the whole function, among its leading comments
	addLine("\$say hi")
}

function("old") { suppress(MacroCheck) }        // the whole function
predicate("is_night") { suppress(UndefinedReferenceCheck) } // any resource
```

`suppress(...)` works whatever the file starts with. A JSON file takes `suppress(...)` only, since it can't hold a comment.
On an external pack, `# kore:ignore` and `# kore:ignore-file` work in `.mcfunction` files the same way.

## Write your own check

```kotlin
object NoTodoLines : PackCheck {
	override val defaultSeverity = Severity.WARNING
	override val id = "no-todo-lines"

	override fun check(index: PackIndex) = index.functions.flatMap { function ->
		function.lines.withIndex().filter { "TODO" in it.value }.map {
			Diagnostic(this, DiagnosticLocation(function.id, ResourceKinds.FUNCTION, it.index + 1), "still has a TODO")
		}
	}
}
```

The `PackIndex` gives the `functions` (their `lines` are those of the written file), the JSON `resources`, `isDefined(kind, id)`
and `isMissing(ResourceKinds.PREDICATE, "my_pack:is_night")`, `true` only for an id of an owned namespace that the pack never
defines. `# kore:ignore no-todo-lines` works on it too.

## Limits

- **Registries** are read only by `unknown-vanilla-id`, so `@e[typ=pig]` passes.
- **Permission levels aren't read.** `op Steve` passes.
- **Text components** are read only for the `run_command` of click events and dialog actions.
- **Overlays** of an external pack are checked only when they apply to Minecraft 26.3.
- **A pack for other versions** (no 121 in its `pack.mcmeta` formats) gets no command syntax check, only an `INFO`.

## What to read next

- [Configuration](https://kore.ayfri.com/docs/guides/configuration.md) - every option of the `configuration { }` block
- [Optimization](https://kore.ayfri.com/docs/guides/optimization.md) - the passes that run just before validation
- [Macros](https://kore.ayfri.com/docs/commands/macros.md) - `$(variable)` lines
