Skip to content

Empty messages payload reaches agent loop and crashes with IndexError #3303

@YizukiAme

Description

@YizukiAme

AI Disclosure

  • This issue was written entirely by a human
  • This issue was written with AI assistance (e.g. Copilot, ChatGPT, Claude) and reviewed and edited by a human
  • I have read the AI Policy and agree to its terms

Human Verification

I have read the AI policy and I confirm this issue was reviewed by a human.

Describe the bug

LettaRequest.validate_input_or_messages only rejects messages is None; it does not reject messages=[]. All V2/V3 agent entrypoints call _prepare_in_context_messages_no_persist_async, which immediately dereferences input_messages[0].

Sending { "messages": [] } bypasses validation and crashes with IndexError, returning 500 instead of 4xx.

# letta/schemas/letta_request.py
if self.input is None and self.messages is None:
    raise ValueError("Must specify either 'input' or 'messages'.")
# messages=[] passes this check ↑

# letta/agents/helpers.py
if input_messages[0].type == "tool_return":  # ← IndexError

Fix: Reject empty arrays in the validator:

if self.messages is not None and len(self.messages) == 0:
    raise ValueError("'messages' must not be empty.")

How are you running Letta?

From source

Operating System

Linux

Letta Version

latest main

Model

No response

Steps to Reproduce

curl -X POST http://localhost:8283/v1/agents/{agent_id}/messages
-H "Content-Type: application/json"
-d '{"messages": []}'

→ 500 Internal Server Error (IndexError)

Expected: 400/422 Validation Error

Relevant Logs / Screenshots

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions