Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

fill_missing_values

Handle missing data by replacing with a custom value or removing affected rows.

Instructions

Fill or remove missing values.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
strategyNodrop
valueNo
columnsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core implementation of fill_missing_values. Handles all strategies: 'drop', 'fill', 'forward', 'backward', 'mean', 'median', 'mode'. Records operation and returns null counts before/after.
    async def fill_missing_values(
        session_id: str,
        strategy: str = "drop",
        value: Any = None,
        columns: list[str] | None = None,
        ctx: Context = None,
    ) -> dict[str, Any]:
        """
        Fill or remove missing values.
    
        Args:
            session_id: Session identifier
            strategy: One of 'drop', 'fill', 'forward', 'backward', 'mean', 'median', 'mode'
            value: Value to fill with (for 'fill' strategy)
            columns: Specific columns to apply to (None for all)
            ctx: FastMCP context
    
        Returns:
            Dict with success status and fill info
        """
        try:
            manager = get_session_manager()
            session = manager.get_session(session_id)
    
            if not session or session.df is None:
                return {"success": False, "error": "Invalid session or no data loaded"}
    
            df = session.df
            null_counts_before = df.isnull().sum().to_dict()
    
            if columns:
                missing_cols = [col for col in columns if col not in df.columns]
                if missing_cols:
                    return {"success": False, "error": f"Columns not found: {missing_cols}"}
                target_cols = columns
            else:
                target_cols = df.columns.tolist()
    
            if strategy == "drop":
                session.df = df.dropna(subset=target_cols)
            elif strategy == "fill":
                if value is None:
                    return {"success": False, "error": "Value required for 'fill' strategy"}
                session.df[target_cols] = df[target_cols].fillna(value)
            elif strategy == "forward":
                session.df[target_cols] = df[target_cols].fillna(method="ffill")
            elif strategy == "backward":
                session.df[target_cols] = df[target_cols].fillna(method="bfill")
            elif strategy == "mean":
                for col in target_cols:
                    if df[col].dtype in ["int64", "float64"]:
                        session.df[col] = df[col].fillna(df[col].mean())
            elif strategy == "median":
                for col in target_cols:
                    if df[col].dtype in ["int64", "float64"]:
                        session.df[col] = df[col].fillna(df[col].median())
            elif strategy == "mode":
                for col in target_cols:
                    mode_val = df[col].mode()
                    if len(mode_val) > 0:
                        session.df[col] = df[col].fillna(mode_val[0])
            else:
                return {"success": False, "error": f"Unknown strategy: {strategy}"}
    
            null_counts_after = session.df.isnull().sum().to_dict()
    
            session.record_operation(
                OperationType.FILL_MISSING,
                {
                    "strategy": strategy,
                    "value": str(value) if value is not None else None,
                    "columns": target_cols,
                },
            )
    
            return {
                "success": True,
                "strategy": strategy,
                "rows_before": len(df),
                "rows_after": len(session.df),
                "null_counts_before": null_counts_before,
                "null_counts_after": null_counts_after,
            }
    
        except Exception as e:
            logger.error(f"Error filling missing values: {e!s}")
            return {"success": False, "error": str(e)}
  • FastMCP tool decorator wrapper for fill_missing_values. Defines the tool signature and delegates to the actual implementation in tools/transformations.py.
    @mcp.tool
    async def fill_missing_values(
        session_id: str,
        strategy: str = "drop",
        value: Any = None,
        columns: list[str] | None = None,
        ctx: Context = None,
    ) -> dict[str, Any]:
        """Fill or remove missing values."""
        return await _fill_missing_values(session_id, strategy, value, columns, ctx)
  • Import of the fill_missing_values function from the transformations module, aliased as _fill_missing_values.
    from .tools.transformations import add_column as _add_column
    from .tools.transformations import change_column_type as _change_column_type
    from .tools.transformations import fill_missing_values as _fill_missing_values
    from .tools.transformations import filter_rows as _filter_rows
    from .tools.transformations import remove_columns as _remove_columns
    from .tools.transformations import remove_duplicates as _remove_duplicates
    from .tools.transformations import rename_columns as _rename_columns
    from .tools.transformations import select_columns as _select_columns
    from .tools.transformations import sort_data as _sort_data
  • Tool listed under 'data_manipulation' capabilities in the server's capability description.
    "fill_missing_values",
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose behavioral traits. It only states the action but not side effects (e.g., in-place modification), data requirements, or error conditions. This is insufficient for safe invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely short (four words), which is efficient but comes at the cost of missing critical information. It should be longer to cover parameters and usage.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 4 parameters, 0% schema coverage, and no annotations, the description is far from complete. Even with an output schema, the description fails to explain invocation context or return values.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, yet the description adds no parameter explanations. The strategy parameter's possible values, the purpose of 'value', and the scope of 'columns' are completely unexplained.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Fill or remove missing values' clearly states the tool's action on missing values. It distinguishes from sibling tools like 'detect_outliers' or 'remove_duplicates', though it could be more specific about the filling strategies.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No usage guidelines provided. The description does not indicate when to use fill vs remove, or how to choose among sibling tools. The agent receives no contextual cues for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/santoshray02/csv-editor'

If you have feedback or need assistance with the MCP directory API, please join our Discord server