Skip to content

Conversation

@ranadeepsingh
Copy link
Collaborator

@ranadeepsingh ranadeepsingh commented Dec 11, 2025

Related Issues/PRs

#2444 - caused the bug and divergence
#2456 - suggested partial fix

What changes are proposed in this pull request?

Fix bug in OpenAIEmbedding when input is None/Null it was giving Null Pointer Exception.
Revamped and changed OpenAIEmbedding and OpenAIPrompt to return None/Null whne input is None/Null regardless of returnUsage is True or False.

  • Add tests for null case so this bug doesn't occur again

How is this patch tested?

  • I have written tests (not required for typo or doc fix) and confirmed the proposed feature/bug-fix/change works.

Does this PR change any dependencies?

  • No. You can skip this section.
  • Yes. Make sure the dependencies are resolved correctly, and list changes here.

Does this PR add a new feature? If so, have you added samples on website?

  • No. You can skip this section.
  • Yes. Make sure you have added samples following below steps.
  1. Find the corresponding markdown file for your new feature in website/docs/documentation folder.
    Make sure you choose the correct class estimators/transformers and namespace.
  2. Follow the pattern in markdown file and add another section for your new API, including pyspark, scala (and .NET potentially) samples.
  3. Make sure the DocTable points to correct API link.
  4. Navigate to website folder, and run yarn run start to make sure the website renders correctly.
  5. Don't forget to add <!--pytest-codeblocks:cont--> before each python code blocks to enable auto-tests for python samples.
  6. Make sure the WebsiteSamplesTests job pass in the pipeline.

@github-actions
Copy link

Hey @ranadeepsingh 👋!
Thank you so much for contributing to our repository 🙌.
Someone from SynapseML Team will be reviewing this pull request soon.

We use semantic commit messages to streamline the release process.
Before your pull request can be merged, you should make sure your first commit and PR title start with a semantic prefix.
This helps us to create release messages and credit you for your hard work!

Examples of commit messages with semantic prefixes:

  • fix: Fix LightGBM crashes with empty partitions
  • feat: Make HTTP on Spark back-offs configurable
  • docs: Update Spark Serving usage
  • build: Add codecov support
  • perf: improve LightGBM memory usage
  • refactor: make python code generation rely on classes
  • style: Remove nulls from CNTKModel
  • test: Add test coverage for CNTKModel

To test your commit locally, please follow our guild on building from source.
Check out the developer guide for additional guidance on testing your change.

@ranadeepsingh
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ranadeepsingh ranadeepsingh changed the title bugfix: Fix null cases for openai prompt and embeddings fix: Fix null cases for openai prompt and embeddings Dec 11, 2025
@ranadeepsingh ranadeepsingh changed the title fix: Fix null cases for openai prompt and embeddings fix: Null cases for openai prompt and embeddings Dec 11, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a NullPointerException bug in OpenAIEmbedding and OpenAIPrompt transformers when input is null. The fix ensures both transformers return null output when input is null, regardless of the returnUsage parameter setting.

Key Changes:

  • Modified OpenAIPrompt to wrap output in when(parsedCol.isNotNull, ...) for both usage-enabled and usage-disabled modes
  • Modified OpenAIEmbedding to wrap output in when(responseCol.isNotNull, ...) for both usage-enabled and usage-disabled modes
  • Added comprehensive tests for null input handling in both transformers with both returnUsage=true and returnUsage=false

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPrompt.scala Added null-safety checks in withUsageColumn method to return null when parsedCol is null, for both struct (with usage) and plain (without usage) output cases
cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbedding.scala Added null-safety checks in transform method to return null when responseCol is null, for both struct (with usage) and plain vector output cases, plus imported when function
cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPromptSuite.scala Added two new tests for null input handling with both returnUsage=false and returnUsage=true; refactored test names to remove "Gpt 4" references and cleaned up unused test fixtures
cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbeddingsSuite.scala Added two new tests for null input handling with both returnUsage=false and returnUsage=true

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter
Copy link

codecov-commenter commented Dec 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.35%. Comparing base (bfa8c46) to head (13bb3eb).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2457      +/-   ##
==========================================
+ Coverage   84.34%   84.35%   +0.01%     
==========================================
  Files         335      335              
  Lines       17723    17729       +6     
  Branches     1616     1621       +5     
==========================================
+ Hits        14948    14956       +8     
+ Misses       2775     2773       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ranadeepsingh ranadeepsingh merged commit b979064 into microsoft:master Dec 11, 2025
78 of 79 checks passed
@ranadeepsingh ranadeepsingh deleted the rana/fix-returnusage-with-nulls branch December 11, 2025 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants