[GH-ISSUE #7653] Validation of Keys and Subkeys in Ollama API JSON Objects #4884

Open
opened 2026-04-12 15:54:53 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @d-kleine on GitHub (Nov 13, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7653

Originally assigned to: @ParthSareen on GitHub.

Problem:
When interacting with the Ollama API, developers may inadvertently pass incorrect keys or subkeys in their requests (e.g., due to typos or misunderstanding of the expected structure). Currently, the API does not provide feedback when this occurs, which can lead to silent failures where options are ignored without notifying the user. This behavior makes debugging difficult and increases the likelihood of unintended behavior.

Proposed Solution:
Implement a validation mechanism that checks for the existence of valid keys and subkeys in the JSON request object. If an invalid key or subkey is detected, return an informative error message detailing which key or subkey is incorrect. This will help developers quickly identify issues in their request payloads.

Expected Behavior:

  1. Validation on Request Submission: When a request is made to any endpoint (e.g., /generate, /chat), the API should validate all provided keys and subkeys against a predefined schema.
  2. Error Response for Invalid Keys: If an invalid key or subkey is detected, return an error response with a message such as:
    KeyError("Invalid key 'num_predct' in 'options'. Did you mean 'num_predict'?")
    
  3. Graceful Handling of Missing Required Keys: If a required key (e.g., "model", "prompt") is missing, return an error indicating which required key is missing:
    KeyError("Missing required key 'model'.")
    

Benefits:

  1. Improved Usability: Developers will receive immediate feedback when they make mistakes in their request payloads, reducing debugging time.
  2. Reduced Silent Failures: By explicitly notifying users of invalid keys or subkeys, you can eliminate silent failures where options are ignored without warning.
  3. Increased Confidence in Requests: Developers can be confident that all provided options are being processed as intended.
Originally created by @d-kleine on GitHub (Nov 13, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7653 Originally assigned to: @ParthSareen on GitHub. **Problem:** When interacting with the Ollama API, developers may inadvertently pass incorrect keys or subkeys in their requests (e.g., due to typos or misunderstanding of the expected structure). Currently, the API does not provide feedback when this occurs, which can lead to silent failures where options are ignored without notifying the user. This behavior makes debugging difficult and increases the likelihood of unintended behavior. **Proposed Solution:** Implement a validation mechanism that checks for the existence of valid keys and subkeys in the JSON request object. If an invalid key or subkey is detected, return an informative error message detailing which key or subkey is incorrect. This will help developers quickly identify issues in their request payloads. ### Expected Behavior: 1. **Validation on Request Submission:** When a request is made to any endpoint (e.g., `/generate`, `/chat`), the API should validate all provided keys and subkeys against a predefined schema. 2. **Error Response for Invalid Keys:** If an invalid key or subkey is detected, return an error response with a message such as: ```python KeyError("Invalid key 'num_predct' in 'options'. Did you mean 'num_predict'?") ``` 4. **Graceful Handling of Missing Required Keys:** If a required key (e.g., `"model"`, `"prompt"`) is missing, return an error indicating which required key is missing: ```python KeyError("Missing required key 'model'.") ``` ### Benefits: 1. **Improved Usability:** Developers will receive immediate feedback when they make mistakes in their request payloads, reducing debugging time. 2. **Reduced Silent Failures:** By explicitly notifying users of invalid keys or subkeys, you can eliminate silent failures where options are ignored without warning. 3. **Increased Confidence in Requests:** Developers can be confident that all provided options are being processed as intended.
GiteaMirror added the feature requestapi labels 2026-04-12 15:54:53 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#4884