How to Upgrade Dify to 1.9.1 and Resolve LLM Iterator Errors
This guide walks you through upgrading Dify using Docker Compose or source code deployment, running required migration commands, backing up data, and fixing the "Invalid context structure" error caused by iterator output changes in version 1.9.1, with detailed code snippets and troubleshooting steps.
Upgrade Steps
Important Notice After upgrading, run the following migration to convert existing datasource credentials: uv run flask transform-datasource-credentials
1. Docker Compose Deployment
Backup custom docker-compose.yaml (optional):
cd docker
cp docker-compose.yaml docker-compose.yaml.$(date +%s).bakPull the latest code from the main branch:
git checkout 1.9.1
git pull origin 1.9.1Stop services (run in the Docker directory): docker compose down Backup data: tar -cvf volumes-$(date +%s).tgz volumes Upgrade services:
docker compose up -d2. Source Code Deployment
Stop API server, worker, and web frontend.
Fetch the latest code from the release branch: git checkout 1.9.1 Update Python dependencies:
cd api
uv syncRun migration scripts:
uv run flask db upgrade
uv run flask transform-datasource-credentialsAfter containers start, run the credential migration:
docker exec -it docker-api-1 uv run flask transform-datasource-credentialsUpgrade Issues
1. Knowledge base iterator output to LLM throws error: "Run failed: Invalid context structure: xxx"
1.1 Symptom The iterator output format changed after upgrade, causing the LLM node to reject the context.
1.2 Root Cause The LLM node expects either a string or an array of objects each containing a content key. After the upgrade, the iterator returns a nested array of objects, which lacks the required content field at the top level.
1.3 Fix Insert a code execution node between the iterator and the LLM node to flatten the nested array and ensure each object has a content key. Example Python code:
from typing import List
def main(output: List[List[str]]):
flattened = [item for sublist in output for item in sublist]
return {"result": " ".join(flattened)}The change was introduced in Dify 1.9.1 due to workflow engine refactoring and new parallel mode support, which now collects each parallel job's output into an ordered list without automatically flattening it.
Until an official fix is released, manually flatten the iterator output in downstream code nodes as shown above.
Architect's Alchemy Furnace
A comprehensive platform that combines Java development and architecture design, guaranteeing 100% original content. We explore the essence and philosophy of architecture and provide professional technical articles for aspiring architects.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
