Fatal error in ToolPluginBase::getReadableOutput() when tool output entity is NULL
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3573094. -->
Reported by: [ajits](https://www.drupal.org/user/981944)
Related to !71
>>>
<p>[Tracker]<br>
<strong>Update Summary: </strong>Fatal error in ToolPluginBase::getReadableOutput() when tool output entity is NULL<br>
<strong>Short Description: </strong>[One-line issue summary for stakeholders]<br>
<strong>Check-in Date: </strong>02/12/2026<br>
<em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br>
[/Tracker]</p>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>I noticed this error when trying to switch to the Live workspace using the <a href="https://www.drupal.org/project/tool_workspace">tool_workspace</a> module.<br>
<code>ToolPluginBase::getReadableOutput()</code> throws a fatal error when a tool plugin returns <code>NULL</code> for an <code>EntityContextDefinition</code> output. The code assumes the entity value is always a valid object, but output definitions can be declared as <code>required: FALSE</code>, allowing <code>NULL</code> values. The "Live" workspace isn't a valid entity object.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ul>
<li>Enable the tool_workspace and tool_ai_connector modules</li>
<li>Ensure no workspace is active (i.e., viewing the Live site)</li>
<li>Invoke the workspace_get_active tool via the AI function call interface</li>
</ul>
<p><strong>Actual result</strong></p>
<blockquote><p>TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given in method_exists() (line 145 of modules/contrib/tool/modules/tool_ai_connector/src/Plugin/AiFunctionCall/ToolPluginBase.php).
</p></blockquote>
<p><strong>Expected result</strong>: The tool should handle <code>NULL</code> entity outputs gracefully.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Check if there is a valid entity loaded.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>Merge request and reviews.</p>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>None</p>
<h3 id="summary-api-changes">API changes</h3>
<p>None</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>None</p>
issue