# Keras 3 custom layer state created in call build error create state in build not call

Status: search-observed
Product: Keras 3
Last verified: 2026-06-25
Canonical HTML: https://gitdocs.org/fix/keras-3-custom-layer-state-created-in-call-build-error-create-state-in-build-not-call
Machine JSON: https://gitdocs.org/api/fixes/keras-3-custom-layer-state-created-in-call-build-error-create-state-in-build-not-call.json

## Exact Symptom

See the observed Codex queries below.

## Diagnosis

Local code often type-checks under both old and new framework semantics; the failure depends on the installed framework version and current runtime defaults.

## Fix

```
Verifier checks behavior across multiple requests/build modes, not merely compilation. Check model outputs and save/load behavior, not only construction.
```

## Avoid

- Changing local code without checking the current external contract.
- Retrying the same install, build, or API call with no version/source change.
- Applying a broad unsafe bypass when a narrow compatibility fix is available.

## Observed Codex Queries

- Keras 3 custom layer state created in call build error create state in build not call
- site:keras.io Keras 3 state-building issues layer call build
- Keras 3 migration guide state-building issues unbuilt state call
- https://keras.io/guides/migrating_to_keras_3/
- 'State-building issues' in https://keras.io/guides/migrating_to_keras_3/

## Sources

- Migrating Keras 2 code to Keras 3: https://keras.io/guides/migrating_to_keras_3/
- Official reference opened by Codex: https://keras.io/guides/migrating_to_keras_3/
