crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] ExcelKnowledgeSource rewrites cell values: 12 becomes 12.0, 01234 becomes 1234, N/A becomes blank

Open L4XB opened this issue 1 month ago • 2 comments

Description

ExcelKnowledgeSource reads each sheet with pd.read_excel(xl, sheet_name), and pandas infers a dtype for every column. As a result, the text that gets chunked and embedded differs from what the workbook holds:

  • A column of whole numbers with one blank cell becomes float, so 12 is stored as 12.0.
  • Text that looks numeric loses its leading zeros: a ZIP code or ID typed as text, 01234, becomes 1234, or 1234.0 next to a blank.
  • Cells whose text is one of pandas' default NA values (N/A, NA, NULL, NaN, null, n/a, …) are emptied, so a "Status: N/A" cell carries no information.

Steps to Reproduce

from pathlib import Path
from openpyxl import Workbook
from crewai.knowledge.source.excel_knowledge_source import ExcelKnowledgeSource

wb = Workbook()
ws = wb.active
ws.append(["SKU", "Qty", "Zip", "Status"])
ws.append(["A1", 12, "01234", "N/A"])
ws.append(["A2", None, "02134", "NULL"])
wb.save("stock.xlsx")

source = ExcelKnowledgeSource(file_paths=[Path("stock.xlsx")])
print(source.content[Path("stock.xlsx")]["Sheet"])

Expected behavior

SKU,Qty,Zip,Status
A1,12,01234,N/A
A2,,02134,NULL

Actual

SKU,Qty,Zip,Status
A1,12.0,1234,
A2,,2134,

Possible Solution

Read the cells as written: pd.read_excel(xl, sheet_name, dtype=str, keep_default_na=False). Empty cells still come out empty.

crewAI main (9c24fda7f), pandas 2.2.3, openpyxl 3.1.5, Python 3.12, macOS.

L4XB avatar Oct 21 '26 18:10 L4XB

I'd like to pick this up. The fix reads each sheet with dtype=str, keep_default_na=False so the stored CSV keeps the values as stored in the workbook, and I'll add a regression test that builds the workbook from the report above. PR coming shortly.

adarsh6980 avatar Oct 22 '26 08:10 adarsh6980

This is still reproducible on main. A fix is open in #8396. Happy to adjust anything reviewers would like changed.

adarsh6980 avatar Nov 15 '26 09:11 adarsh6980