Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Skills Parameter Passing and Receiving

Skills Parameter Passing and Receiving

Skills do not receive explicit parameters like traditional functions; they sense input information through Claude's context.

Understanding this "implicit parameter passing" mechanism is key to writing practical Skills.


How Skills obtain parameters

When Claude reads a Skill, the entire conversation context becomes that Skill's parameters.

This means what the user says, uploaded files, and conversation history can all become input sources for the Skill.

Input sources Example Description
User's current message "Help me process this PDF" The most direct input
Uploaded files The user uploaded report.pdf Passed in via path or content
Conversation history Data formats discussed earlier Can be referenced in the context
System variables Current date, working directory path Automatically sensed by Claude

Declare expected inputs in SKILL.md

SKILL.md can use natural language descriptions to tell Claude what information to extract from the context.

The following is an example of a Skill that processes CSV files, demonstrating how to declare input expectations in the instructions:

Example


name: csv-analyzer

description: Analyze a user-uploaded CSV file and output a statistical summary. Triggered when the user mentions CSV or tabular data analysis.


CSV Analyzer

Input requirements

The user should provide the following information (obtained from the conversation context):

**

File path

**

: the path of the uploaded CSV file (located in

/

mnt

/

user-data

/

uploads

/

)

**

analysis objective

**

(optional): what the user wants to know, such as

"Find null values"

、

"Statistical distribution"

**

Output formats

**

(optional): table, chart, or text summary

If the above information is unclear, proactively confirm with the user before executing.

The "input requirements" in a Skill are written for Claude itself. Based on this description, Claude will proactively extract information from the context or ask the user follow-up questions when information is insufficient.


Receiving structured parameters through scripts

When a Skill includes a Python or Shell script, parameters are passed via command-line arguments or standard input.

This is exactly the same as how ordinary scripts handle parameters.

Example

File path: scripts/analyze.py

import

argparse

import

pandas

as

pd

def

main

(

)

:

   

Define command-line arguments

   

parser

=

argparse.

ArgumentParser

(

description

=

"CSV file analysis script"

)

   

parser

.

add_argument

(

"file"

,

       

help

=

"Required: CSV file path"

)

   

parser

.

add_argument

(

"--col"

,

     

help

=

"Optional: specify column names to analyze"

)

   

parser

.

add_argument

(

"--limit"

,

type

=

int

,

default

=

10

,

                       

help

=

"Optional: maximum number of rows to display, default 10"

)

    args

=

parser

.

parse_args

(

)

   

Reading a file

    df

=

pd.

read_csv

(

args.

file

)

   

Filter columns as needed

   

if

args.

col

:

        df

=

df

[

[

args.

col

]

]

   

Output statistical information

   

print

(

df.

head

(

args.

limit

)

.

to_string

(

)

)

   

print

(

"\n--- Statistical Summary ---"

)

   

print

(

df.

describe

(

)

)

if

name

==

"main"

:

    main

(

)

How Claude calls this script in SKILL.md:

Example

Execute analysis

After obtaining the file path, run the following command:



bash



  

python scripts



/



analyze.py



<



文件路径



>



[



--col



<



列名



>



]



[



--limit



<



行数



>



]



  

Show the command-line output to the user and provide a text interpretation.


File path parameter handling specifications

User-uploaded files are all located under the /mnt/user-data/uploads/ path.

In Skill scripts, always use absolute paths to access files to avoid path resolution errors.

Example

import

os

Correct: use absolute paths

UPLOAD_DIR

=

"/mnt/user-data/uploads"

file_path

=

os

.

path

.

join

(

UPLOAD_DIR

,

"report.csv"

)

Incorrect: use relative paths (will fail due to different working directories)

file_path = "uploads/report.csv"

Check whether the file exists

if

not

os

.

path

.

exists

(

file_path

)

:

   

print

(

f

"Error: file does not exist → {file_path}"

)

    exit

(

1

)


Parameter validation: check inputs before execution

Skill scripts should always validate that key parameters are legal before execution.

This prevents runtime crashes caused by missing or malformed parameters.

Example

File path: scripts/validate_input.py

import

sys

import

os

def

validate_csv_input

(

file_path:

str

)

bool

:

   

"""Validate whether the CSV file input is valid"""

   

Check whether a file path is provided

   

if

not

file_path:

       

print

(

"Error: no file path provided"

)

       

return

False

   

Check whether the file exists

   

if

not

os

.

path

.

exists

(

file_path

)

:

       

print

(

f

"Error: file does not exist → {file_path}"

)

       

return

False

   

Check the file extension

   

if

not

file_path.

lower

(

)

.

endswith

(

".csv"

)

:

       

print

(

f

"Error: file type not supported, expected .csv, got → {file_path}"

)

       

return

False

   

Check file size (warn if over 100MB)

    size_mb

=

os

.

path

.

getsize

(

file_path

)

/

(

1024

1024

)

   

if

size_mb

100

:

       

print

(

f

"Warning: file is large ({size_mb:.1f} MB), processing may be slow"

)

   

return

True

if

name

==

"main"

:

   

if

len

(

sys

.

argv

)

<

2

:

       

print

(

"Usage: python validate_input.py "

)

       

sys

.

exit

(

1

)

    ok

=

validate_csv_input

(

sys

.

argv

[

1

]

)

   

sys

.

exit

(

0

if

ok

else

1

)

Parameter validation failure messages should clearly state what was expected and what was actually received, so Claude can report the specific reason to the user.