A prompt is an instruction or formatted input that gives a language model context, behavior, tone, boundaries, or a task. In time-series work, prompts convert numerical sequences into natural-language requests and guide the model toward a structured prediction. section 8.0 section 8.6.1
Prompt-based forecasting typically separates two roles:
- A system prompt supplies high-level instructions, such as treating the model as a time-series prediction assistant and specifying the expected numeric representation. section 8.6.1
- A user prompt supplies the input sequence, forecast horizon, and output constraint, such as requesting only the next values. section 8.6.2
- Few-shot and chain-of-thought prompts are identified as generally effective prompt forms, although language models may still forecast poorly because they were not built specifically for forecasting. section 8.10
Forecasting and anomaly detection
A forecasting prompt can describe comma-separated decimal values and ask for the next sequence. A modified system prompt can instead classify each value as anomalous or normal, using outputs such as [0, 0, 0, 1, 0] for an unusually large point. section 8.6.2 section 8.8.1
Listing 8.15 Setting the system prompt
system_prompt = """
You are a helpful assistant that performs time series predictions.
The user will provide a sequence and you will predict the next
sequence.
The sequence is represented by decimal numbers as strings separated by
commas.
"""
Inspect a concrete system prompt that assigns the forecasting role, defines the input format, and requests the next sequence. section 8.6.1
Listing 8.16 Function to forecast via API call
def prompt_forecast(
df,
horizon,
context_len,
target_col
):
input_values = df[f'{target_col}'].iloc[-context_len:]
➥.values.tolist() #1
response = requests.post( #2
url="https://openrouter.ai/api/v1
➥/chat/completions", #3
headers={
"Authorization":
➥f"Bearer {OPENROUTER_API_KEY}", #4
},
data=json.dumps({ #5
"model":
➥"meta-llama/llama-3.2-3b-instruct:free", #6
"messages": [
{
"role": "system",
"content": system_prompt #7
},
{
"role": "user",
"content": f"The past values of the series are {input_values}.
➥What will be the next {horizon} values? Just output the
➥next values and nothing else." #8
}
]
})
)
response_json = response.json() #9
content = response_json['choices'][0]
➥['message']['content'] #10
if content.startswith('[') and content.endswith(']'):
preds = json.loads(content) #11
else:
wrapped = f'[{content}]'
preds = json.loads(wrapped)
return preds
Inspect the API implementation that sends system and user messages, authenticates the request, parses JSON, and extracts forecast values. section 8.6.2

















































