keras-team/keras · error · ValueError
Invalid AUC curve value: "{key}". Expected values are ["PR",
Error message
Invalid AUC curve value: "{key}". Expected values are ["PR", "ROC", "PRGAIN"] What it means
AUC accepts its curve parameter as an AUCCurve enum or a case-insensitive string. AUCCurve.from_str() recognizes only the keys roc/ROC, pr/PR and prgain/PRGAIN, and raises this ValueError for anything else. Names like 'precision-recall' or 'ROCC' are rejected.
Source
Thrown at keras/src/metrics/metrics_utils.py:58
class AUCCurve(Enum):
"""Type of AUC Curve (ROC or PR)."""
ROC = "ROC"
PR = "PR"
PRGAIN = "PRGAIN"
@staticmethod
def from_str(key):
if key in ("pr", "PR"):
return AUCCurve.PR
elif key in ("roc", "ROC"):
return AUCCurve.ROC
elif key in ("prgain", "PRGAIN"):
return AUCCurve.PRGAIN
else:
raise ValueError(
f'Invalid AUC curve value: "{key}". '
'Expected values are ["PR", "ROC", "PRGAIN"]'
)
class AUCSummationMethod(Enum):
"""Type of AUC summation method.
https://en.wikipedia.org/wiki/Riemann_sum)
Contains the following values:
* 'interpolation': Applies mid-point summation scheme for `ROC` curve. For
`PR` curve, interpolates (true/false) positives but not the ratio that is
precision (see Davis & Goadrich 2006 for details).
* 'minoring': Applies left summation for increasing intervals and right
summation for decreasing intervals.
* 'majoring': Applies right summation for increasing intervals and left
summation for decreasing intervals.View on GitHub (pinned to 7a34a03db6)
Solutions
- Use exactly 'ROC', 'PR', or 'PRGAIN' (case-insensitive).
- For a precision-recall AUC pass curve='PR'; for gain curves pass 'PRGAIN'.
- Or pass the enum directly: keras.metrics.AUC(curve=AUCCurve.PR) (the string form is preferred).
Example fix
# before auc = keras.metrics.AUC(curve='precision-recall') # after auc = keras.metrics.AUC(curve='PR')
Defensive patterns
Strategy: validation
Validate before calling
VALID_CURVES = {'roc', 'pr', 'prgain'}
def check_curve(c):
if isinstance(c, str) and c.lower() not in VALID_CURVES:
raise ValueError(f'curve must be one of {sorted(VALID_CURVES)}')
return c Type guard
def is_valid_auc_curve(c) -> bool:
return not isinstance(c, str) or c.lower() in {'roc', 'pr', 'prgain'} Prevention
- Whitelist AUC curve strings from configs before passing them to AUC.
When it happens
Trigger: Calling keras.metrics.AUC(curve='precision-recall') or AUC(curve='sketch-roc') - any string other than the roc/pr/prgain variants.
Common situations: Assuming scikit-learn style naming ('precision', 'roc_auc_score') transfers to Keras; typo'd values coming from config files.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Invalid AUC summation method value: "{key}". Expected values
- Invalid `curve` argument value "{curve}". Expected one of: {
- Invalid `summation_method` argument value "{summation_method
- Argument `num_thresholds` must be an integer > 1. Received:
- `num_labels` is needed only when `multi_label` is True.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/4d2ca336bf2a512f.
Report an issue: GitHub.