Hi, I have been trying for days to deploy the python code with pydanticai. Locally, everything works well, but on vercel, I am constantly getting FUNCTION_INVOCATION_FAILED error. when I check the log, I see the following:
Traceback (most recent call last):File "/var/task/vc__handler__python.py", line 14, in <module>__vc_spec.loader.exec_module(__vc_module)File "<frozen importlib._bootstrap_external>", line 995, in exec_moduleFile "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removedFile "/var/task/src/main_vercel.py", line 1, in <module>from fastapi import FastAPI, Request, WebSocketFile "/var/task/fastapi/__init__.py", line 7, in <module>from .applications import FastAPI as FastAPIFile "/var/task/fastapi/applications.py", line 16, in <module>from fastapi import routingFile "/var/task/fastapi/routing.py", line 24, in <module>from fastapi import paramsFile "/var/task/fastapi/params.py", line 5, in <module>from fastapi.openapi.models import ExampleFile "/var/task/fastapi/openapi/models.py", line 4, in <module>from fastapi._compat import (File "/var/task/fastapi/_compat.py", line 21, in <module>from fastapi.exceptions import RequestErrorModelFile "/var/task/fastapi/exceptions.py", line 3, in <module>from pydantic import BaseModel, create_modelFile "<frozen importlib._bootstrap>", line 1412, in _handle_fromlistFile "/var/task/pydantic/__init__.py", line 421, in __getattr__module = import_module(module_name, package=package)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/var/lang/lib/python3.12/importlib/__init__.py", line 90, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/var/task/pydantic/main.py", line 34, in <module>from ._internal import (File "/var/task/pydantic/_internal/_model_construction.py", line 25, in <module>from ._generate_schema import GenerateSchemaFile "/var/task/pydantic/_internal/_generate_schema.py", line 42, in <module>from uuid import UUIDFile "/var/task/uuid.py", line 138if not 0 <= time_low < 1<<32L:^SyntaxError: invalid decimal literalPython process exited with exit status: 1. The logs above can help with debugging the issue.the main_vercel.py script is the following:
from fastapi import FastAPI, Request, WebSocketfrom fastapi.middleware.cors import CORSMiddlewarefrom dotenv import load_dotenvimport osfrom src.routers import ( image_router, auth_router, financial_stats_router, receipt, financial_analytics_router, store, tags, spending_sheet, categories, user_settings_router)from src.websockets.websocket_manager import managerfrom src.database.db_utils import init_dbfrom src.type_defs.dynamic_types import initialize_typesfrom contextlib import asynccontextmanager# Load environment variablesload_dotenv()# Define lifespan first@asynccontextmanagerasync def lifespan(app: FastAPI): """Lifespan context manager for FastAPI app""" # Startup await init_db()these are essential imports in some other script:
from dataclasses import dataclassimport asynciofrom pydantic import BaseModel, Fieldfrom pydantic_ai import Agent, RunContextfrom uuid import UUID, uuid4this is the requirements.txt file:
aiohappyeyeballs==2.4.4aiohttp==3.11.11aiosignal==1.3.2annotated-types==0.7.0anyio==4.8.0asyncpg==0.29.0attrs==25.1.0bcrypt==4.2.1boto3==1.29.0botocore==1.32.7cachetools==5.5.1certifi==2025.1.31cffi==1.17.1charset-normalizer==3.4.1click==8.1.8colorama==0.4.6cryptography==44.0.0deprecation==2.1.0distro==1.9.0dnspython==2.7.0ecdsa==0.19.0email_validator==2.2.0eval_type_backport==0.2.2fastapi==0.115.0fastavro==1.10.0filelock==3.17.0frozenlist==1.5.0fsspec==2025.2.0google-auth==2.38.0greenlet==3.1.1I would be thankful if anyone helped me with solving the issue. I suspect there might be an issue with pydantic v2.x but I can't use older version due to other dependencies.