SignatureFieldNotFoundError
dspy.errors.SignatureFieldNotFoundError
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in <module>
signature = dspy.load_signature(data)
File "/usr/local/lib/python3.10/site-packages/dspy/__init__.py", line 88, in load_signature
raise SignatureFieldNotFoundError("Signature field not found in input data")
dspy.errors.SignatureFieldNotFoundError: Signature field not found in input data Why it happens
DSPy expects a specific signature field in the input data or configuration to identify the data schema or model signature. If this field is missing, misspelled, or incorrectly nested, DSPy cannot proceed and raises this error.
Detection
Check for the presence of the required signature field in your input data or configuration before calling DSPy functions, or catch SignatureFieldNotFoundError to log and handle missing signatures gracefully.
Causes & fixes
The input data dictionary does not contain the required 'signature' key.
Ensure the input data includes the 'signature' field exactly as expected by DSPy, with correct casing and nesting.
The signature field is present but nested inside another dictionary or under a different key name.
Flatten the input data structure or rename keys so that the signature field is accessible at the expected top-level key.
Using an outdated or incompatible DSPy version that expects a different signature field format.
Upgrade DSPy to the latest compatible version and verify the signature field format matches the current DSPy documentation.
Code: broken vs fixed
import os
import dspy
data = {
"user_id": 123,
"payload": {"value": 42}
}
# This line raises SignatureFieldNotFoundError because 'signature' field is missing
signature = dspy.load_signature(data)
print(signature) import os
import dspy
# Added the required 'signature' field to input data
data = {
"user_id": 123,
"signature": "v1.0",
"payload": {"value": 42}
}
signature = dspy.load_signature(data) # Fixed: signature field present
print(signature) Workaround
Wrap calls to DSPy signature loading in try/except SignatureFieldNotFoundError, then manually inject a default or fallback signature field before retrying.
Prevention
Always validate input data schemas to include the required signature field before passing to DSPy, and use schema validation tools to catch missing fields early.