{"record":{"id":"c96a1817c4ac8f7a","repo":"langflow-ai/langflow","slug":"error-serializing-vertex-build-response-exc","errorCode":null,"errorMessage":"Error serializing vertex build response: {exc}","messagePattern":"Error serializing vertex build response: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/backend/base/langflow/api/build.py","lineNumber":831,"sourceCode":"        # Why: the background path never enters Graph.process(), so the pause boundary must live in this driver.\n        await graph.check_and_handle_pause()\n        try:\n            vertex_build_response: VertexBuildResponse = await _build_vertex(vertex_id, graph, event_manager)\n        except asyncio.CancelledError:\n            await logger.ainfo(\"Build cancelled\")\n            raise\n\n        # Accumulate the vertex timedelta\n        if vertex_build_response.data.timedelta is not None:\n            vertex_timedeltas.append(vertex_build_response.data.timedelta)\n\n        # send built event or error event\n        try:\n            vertex_build_response_json = vertex_build_response.model_dump_json()\n            build_data = json.loads(vertex_build_response_json)\n        except Exception as exc:\n            msg = f\"Error serializing vertex build response: {exc}\"\n            raise ValueError(msg) from exc\n\n        event_manager.on_end_vertex(\n            data={\"build_data\": build_data, \"output_meta\": _output_meta_for_vertex(graph, vertex_id)}\n        )\n\n        if vertex_build_response.valid and vertex_build_response.next_vertices_ids:\n            tasks = []\n            for next_vertex_id in vertex_build_response.next_vertices_ids:\n                task = asyncio.create_task(\n                    build_vertices(\n                        next_vertex_id,\n                        graph,\n                        event_manager,\n                        vertex_timedeltas,\n                    )\n                )\n                tasks.append(task)\n            await asyncio.gather(*tasks)","sourceCodeStart":813,"sourceCodeEnd":849,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/build.py#L813-L849","documentation":"A ValueError raised when a vertex build succeeded but its VertexBuildResponse cannot be serialized with model_dump_json()/json.loads() before emitting the on_end_vertex event. This indicates the response model contains data that pydantic cannot dump to JSON — typically non-serializable objects placed in the output data by a custom component.","triggerScenarios":"A component returning raw objects (DB cursors, tensors, file handles, arbitrary class instances) in its Output data instead of langflow Message/Data types; outputs whose type fails pydantic-core serialization (e.g. objects with __slots__ cycles, numpy types without serializers).","commonSituations":"Custom components returning SDK objects directly instead of calling .data or converting to str/Message; library upgrades changing pydantic serialization strictness.","solutions":["In the failing component, convert the output to a supported type (Message, Data, str, or a plain dict/list of primitives) before returning","If returning rich objects, implement model_serializer / dict() conversion, or use repr()/str() for display outputs","Pin consistent pydantic versions across the workspace if serialization behavior changed after upgrade","Reproduce by building only that vertex to confirm the serialization fix"],"exampleFix":"# before\nreturn Data(data={'result': some_llm_sdk_object})  # not JSON-dumpable\n# after\nreturn Data(data={'result': str(some_llm_sdk_object)})\n# or the idiomatic way:\nreturn Message(text=some_llm_sdk_object.content)","handlingStrategy":"type-guard","validationCode":"# before returning from a custom component, ensure JSON-serializability\nimport json\ndef safe_output(obj) -> str:\n    try:\n        json.dumps(obj)\n        return obj\n    except TypeError:\n        return str(obj)","typeGuard":"from langflow.schema.message import Message\nfrom langflow.schema import Data\nfrom langflow.schema.dataframe import DataFrame\n\ndef is_serializable_output(v) -> bool:\n    return isinstance(v, (Message, Data, DataFrame, str, int, float, bool, list, dict, type(None)))","tryCatchPattern":"try { ... } finally { /* vertex serialization failure is a server bug-class error: fix the component rather than catching at the edge */ }","preventionTips":["Return langflow types (Message/Data) from component outputs, never raw SDK objects","Unit-test custom components with json.dumps(output) as an assertion","After pydantic upgrades, smoke-test flows with the richest output components"],"tags":["serialization","pydantic","vertex","custom-component"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}