{"record":{"id":"5b3bc76df95c477e","repo":"lancedb/lancedb","slug":"at-least-one-record-or-a-schema-needs-to-be-provid","errorCode":null,"errorMessage":"At least one record or a schema needs to be provided","messagePattern":"At least one record or a schema needs to be provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodejs/lancedb/arrow.ts","lineNumber":427,"sourceCode":"  if (opt.schema !== undefined && opt.schema !== null) {\n    schema = sanitizeSchema(opt.schema);\n    schema = validateSchemaEmbeddings(\n      schema as Schema,\n      data,\n      options?.embeddingFunction,\n    );\n  }\n\n  let schemaMetadata = schema?.metadata || new Map<string, string>();\n  if (metadata !== undefined) {\n    schemaMetadata = new Map([...schemaMetadata, ...metadata]);\n  }\n\n  if (\n    data.length === 0 &&\n    (options?.schema === undefined || options?.schema === null)\n  ) {\n    throw new Error(\"At least one record or a schema needs to be provided\");\n  } else if (data.length === 0) {\n    if (schema === undefined) {\n      throw new Error(\"A schema must be provided if data is empty\");\n    } else {\n      schema = new Schema(schema.fields, schemaMetadata);\n      return new ArrowTable(schema);\n    }\n  }\n\n  let inferredSchema = inferSchema(data, schema, opt);\n  inferredSchema = new Schema(inferredSchema.fields, schemaMetadata);\n\n  const finalColumns: Record<string, Vector> = {};\n  for (const field of inferredSchema.fields) {\n    finalColumns[field.name] = transposeData(data, field);\n  }\n\n  return new ArrowTable(inferredSchema, finalColumns);","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/lancedb/lancedb/blob/c7b051aff7039333a3f61b79217246c27676806a/nodejs/lancedb/arrow.ts#L409-L445","documentation":"makeArrowTable needs something to build a table from. If the data array is empty and no schema option is supplied, it cannot infer an Arrow schema and throws. This guards against silently creating a table with no columns.","triggerScenarios":"Calling makeArrowTable([]) (or table/db.createTable with an empty records array) without passing options.schema or options.schemaLike.","commonSituations":"Developers inserting records from an upstream API that returned an empty list, or looping over batches where the first batch is empty and they expect LanceDB to infer the schema from later batches.","solutions":["Provide a schema: pass options.schema (an apache-arrow Schema or schema-like object) when data is empty.","Use the dedicated helper makeEmptyTable(schema) instead of calling makeArrowTable([]).","Ensure the data array is non-empty before calling, e.g. filter out empty batches before insertion.","If the schema is known only from existing data, open/read the existing table first and reuse its schema."],"exampleFix":"// before\nawait db.createTable(\"items\", []);\n// after\nimport * as arrow from \"apache-arrow\";\nawait db.createTable(\"items\", [], { schema: new arrow.Schema([\n  new arrow.Field(\"id\", new arrow.Int32()),\n  new arrow.Field(\"name\", new arrow.Utf8()),\n]) });","handlingStrategy":"validation","validationCode":"if (rows.length === 0 && !options?.schema) {\n  throw new Error(\"Provide rows or an explicit schema before creating the table\");\n}","typeGuard":"function hasSchema(o?: { schema?: unknown }): o is { schema: object } {\n  return o?.schema != null;\n}","tryCatchPattern":"try {\n  await db.createTable(name, rows, opts);\n} catch (e) {\n  if (e.message.includes(\"At least one record or a schema\")) {\n    await db.createTable(name, rows, { ...opts, schema: knownSchema });\n  } else throw e;\n}","preventionTips":["Never call createTable/makeArrowTable with a possibly-empty array without a schema.","Use makeEmptyTable(schema) for intentional empty tables.","Guard batch pipelines to skip empty batches or supply a schema up front."],"tags":["schema","empty-data","typescript","arrow"],"backgroundTag":"missing-required-argument","analyzedSha":"c7b051aff7039333a3f61b79217246c27676806a","analyzedAt":"2026-09-08T23:42:37.579Z","contentChangedAt":"2026-09-08T23:42:37.579Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}