Unable to feed value for placeholder tensor
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The TensorFlow error "Unable to feed value for placeholder tensor" means the graph expected input for a placeholder, but no compatible value was supplied when the graph ran. In TensorFlow 1.x, placeholders are explicit graph inputs, so every required placeholder must be fed through feed_dict during Session.run.
The message can also appear in migration work where TensorFlow 1.x graph code is mixed with TensorFlow 2.x habits. The fix is usually to identify which placeholder is missing, confirm its shape and dtype, and make sure the value is fed on every execution path that touches it.
What A Placeholder Represents
In TensorFlow 1.x, placeholders are declarations of inputs that will be provided later:
The graph above is valid, but x does not hold data by itself. The data must be provided when the graph executes.
The Usual Cause: Missing feed_dict
If you try to run y without feeding x, TensorFlow raises the placeholder error:
The fix is to provide a matching value:
That is the direct meaning of the error: the graph required data for x, and no usable feed was given.
Shape And Dtype Mismatches Also Matter
Sometimes a value is fed, but TensorFlow still fails because the feed does not match the placeholder definition. If x expects float32 values with shape [None, 2], then feeding strings, integers with the wrong dtype, or arrays with the wrong second dimension can produce related errors.
That is why debugging should always check three things together:
- placeholder name
- placeholder dtype
- placeholder shape
The placeholder named in the stack trace is usually the fastest starting point.
TensorFlow 2.x Does Not Normally Use Placeholders
In TensorFlow 2.x, eager execution is on by default, and ordinary model code usually works with tensors and function arguments instead of placeholders. That means the long-term fix for many old placeholder problems is to modernize the code rather than to keep patching feed_dict usage.
A simple TensorFlow 2.x equivalent looks like this:
If you are maintaining older graph code, tensorflow.compat.v1 is still available, but it helps to recognize that placeholders belong to the TensorFlow 1.x execution model.
Read The Placeholder Name Carefully
TensorFlow usually includes the placeholder name in the error message. That detail matters because many training graphs have several inputs, and the fastest fix is often simply identifying which placeholder was not fed instead of inspecting the whole graph.
Common Pitfalls
- Running a graph that depends on a placeholder without supplying
feed_dict. - Feeding the wrong placeholder while assuming the names are similar enough.
- Supplying values with the wrong dtype or shape.
- Forgetting that a helper function or training step also needs the same placeholder feed.
- Mixing TensorFlow 1.x placeholder code with TensorFlow 2.x expectations.
Summary
- The error means TensorFlow expected input for a placeholder and did not receive a compatible value.
- In TensorFlow 1.x, fix it by feeding every required placeholder through
feed_dict. - Check the placeholder name, shape, and dtype together.
- TensorFlow 2.x usually avoids placeholders entirely because eager execution is the default.
- If the codebase is old, consider whether migrating away from placeholders is the cleaner long-term fix.

