Skip to content

Error with pydantic > 2 #21

@abhidg

Description

@abhidg

NSQL with manifest-ml gives an error with pydantic > 2 which is installed by default. Tested on Ubuntu 22.04 with Python 3.10.12 from conda-forge:

$ pip install -r requirements.txt
$ pip freeze | grep pydantic
pydantic==2.5.3
pydantic_core==2.14.6

Running with a sample table gives validation errors with pydantic > 2:

DATABASE = "data.db"
#TABLES = []
TABLES = ["table"]  # list of tables to load or [] to load all tables

from db_connectors import SQLiteConnector
from prompt_formatters import RajkumarFormatter
from manifest import Manifest

manifest_client = Manifest(client_name="huggingface", client_connection="http://127.0.0.1:5000")

def get_sql(instruction: str, max_tokens: int = 300) -> str:
    prompt = formatter.format_prompt(instruction)
    res = manifest_client.run(prompt, max_tokens=max_tokens)
    print(res)
    return formatter.format_model_output(res)

# Get the connector and formatter
sqlite_connector = SQLiteConnector(
    database_path=DATABASE
)
sqlite_connector.connect()
if len(TABLES) <= 0:
    TABLES.extend(sqlite_connector.get_tables())

print(f"Loading tables: {TABLES}")

db_schema = [sqlite_connector.get_schema(table) for table in TABLES]
formatter = RajkumarFormatter(db_schema)

sql = get_sql("Number of rows in table?")
print(sql)
print(sqlite_connector.run_sql_as_df(sql))
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Table
pks
  Field required [type=missing, input_value={'name': 'table', 'columns...', dtype='TEXT')]}, input_type=dict]

Also pydantic > 2 conflicts with manifest-ml requirements, but is somehow installed.

Installing pydantic < 2 fixes this:

$ pip install 'pydantic<2'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions